pi-webapp 0.1.52-alpha.2 → 0.1.52-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/extension.js +27 -27
- package/dist/hosted-recovery.js +2 -2
- package/dist/hosted-worker.js +2 -2
- package/package.json +2 -2
- package/web/dist/.vite/manifest.json +4 -4
- package/web/dist/assets/{app-tKAlvGnx.js → app-_Ug70Gwo.js} +6 -6
- package/web/dist/assets/app.js +4 -4
- package/web/dist/assets/{plugin-DJaiYPEQ.js → plugin-0Vwjcj6k.js} +2 -2
- package/web/dist/assets/{plugin-3Ib-WXMi.js → plugin-Bn9YQlEA.js} +2 -2
- package/web/dist/assets/{plugin-DObSoug1.js → plugin-q4wA1M0I.js} +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ruby-CGfRnGY4.js","assets/html-Dkdzkf5m.js","assets/dist-DvRDAAjZ.js","assets/app.js","assets/javascript-qRALF4mN.js","assets/css-COynAVCS.js","assets/xml-Dg-qt816.js","assets/java-C0tX6Zjj.js","assets/sql-BJwLzEN3.js","assets/graphql-BUOosdAq.js","assets/typescript-dAcDzF3q.js","assets/cpp-M92QQ27h.js","assets/c-D2xwndn2.js","assets/shellscript-DugvE863.js","assets/lua-2gStHmQ-.js","assets/yaml-BOAQTz6b.js","assets/php-B4BGKN5F.js","assets/json-Hfsf52vC.js","assets/scss-DOxJ7xu_.js","assets/http-iVoGgZyc.js","assets/rst-DEFIrwXa.js","assets/html-derivative-B-zMOKjI.js","assets/python-_UfA4Rpn.js","assets/cmake-Cf85PuIk.js","assets/latex--YAwAQ5f.js","assets/r-vFiqf_wZ.js","assets/julia-CTkez5_b.js","assets/erlang-9UB0pWNm.js","assets/markdown-BR5vuK2p.js","assets/elixir-DIe8-kxb.js","assets/fsharp-CkcEwvkw.js","assets/perl-C6cfY4X6.js","assets/vue-b-L2NQfY.js","assets/svelte-Cnhqc3fy.js","assets/plugin-
|
|
2
|
-
(function(){try{var e=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]=`f29d5f22-e983-413a-881a-de36830ac37f`,e._sentryDebugIdIdentifier=`sentry-dbid-f29d5f22-e983-413a-881a-de36830ac37f`)}catch{}})();import{_ as e,a as t,c as n,d as r,f as i,g as a,h as o,i as s,l as c,m as l,n as u,o as d,p as f,r as p,s as m,u as h,v as g}from"./dist-DvRDAAjZ.js";import{A as _,C as v,D as y,E as b,M as x,O as S,S as C,T as w,_ as T,a as E,b as D,c as O,d as k,f as ee,g as te,h as ne,i as A,j as re,k as ie,l as j,m as ae,n as oe,o as M,p as se,r as ce,s as le,t as ue,u as de,v as fe,w as pe,y as me}from"./WorkspacePanel.module-7fbly3iv.js";import{a as N,i as he,o as ge,r as _e,s as ve,t as ye}from"./app.js";import{t as be}from"./typescript-dAcDzF3q.js";import{t as xe}from"./shellscript-DugvE863.js";import{t as Se}from"./json-Hfsf52vC.js";var Ce=a((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&&te(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&&te(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,ee=k.port2;k.port1.onmessage=D,O=function(){ee.postMessage(null)}}else O=function(){_(D,0)};function te(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,te(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}}}})),we=a(((e,t)=>{t.exports=Ce()})),Te=a((e=>{var t=we(),n=o(),r=x();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 s(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 c(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 l(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 u(e){if(s(e)!==e)throw Error(i(188))}function d(e){var t=e.alternate;if(!t){if(t=s(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 o=a.alternate;if(o===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===o.child){for(o=a.child;o;){if(o===n)return u(a),e;if(o===r)return u(a),t;o=o.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=o;else{for(var c=!1,l=a.child;l;){if(l===n){c=!0,n=a,r=o;break}if(l===r){c=!0,r=a,n=o;break}l=l.sibling}if(!c){for(l=o.child;l;){if(l===n){c=!0,n=o,r=a;break}if(l===r){c=!0,r=o,n=a;break}l=l.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 p(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)&&p(e.child,t,n,r,i,a))return!0;e=e.sibling}return!1}function m(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 h(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 g(e){var t=[null,null],n=m(e);return n===null||_(t,e,n.child,{foundSelf:!1}),t}function _(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)&&_(e,t,n.child,r))return!0;n=n.sibling}return!1}function v(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 y=null,b=null;function S(e,t,n){return e===n||e===t&&(y=e,!0)}function C(e,t,n){return e===n?(b=e,!1):e===t&&(b!==null&&(y=e),!0)}function w(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 T(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 E=Object.assign,D=Symbol.for(`react.element`),O=Symbol.for(`react.transitional.element`),k=Symbol.for(`react.portal`),ee=Symbol.for(`react.fragment`),te=Symbol.for(`react.strict_mode`),ne=Symbol.for(`react.profiler`),A=Symbol.for(`react.consumer`),re=Symbol.for(`react.context`),ie=Symbol.for(`react.forward_ref`),j=Symbol.for(`react.suspense`),ae=Symbol.for(`react.suspense_list`),oe=Symbol.for(`react.memo`),M=Symbol.for(`react.lazy`),se=Symbol.for(`react.activity`),ce=Symbol.for(`react.legacy_hidden`),le=Symbol.for(`react.memo_cache_sentinel`),ue=Symbol.for(`react.view_transition`),de=Symbol.for(`react.recoverable`),fe=Symbol.iterator;function pe(e){return typeof e!=`object`||!e?null:(e=fe&&e[fe]||e[`@@iterator`],typeof e==`function`?e:null)}var me=Symbol.for(`react.client.reference`);function N(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===me?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case ee:return`Fragment`;case ne:return`Profiler`;case te:return`StrictMode`;case j:return`Suspense`;case ae:return`SuspenseList`;case se:return`Activity`;case ue:return`ViewTransition`}if(typeof e==`object`)switch(e.$$typeof){case k:return`Portal`;case re:return e.displayName||`Context`;case A:return(e._context.displayName||`Context`)+`.Consumer`;case ie:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case oe:return t=e.displayName||null,t===null?N(e.type)||`Memo`:t;case M:t=e._payload,e=e._init;try{return N(e(t))}catch{}}return null}var he=Array.isArray,ge=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,_e=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,ve={pending:!1,data:null,method:null,action:null},ye=[],be=-1;function xe(e){return{current:e}}function Se(e){0>be||(e.current=ye[be],ye[be]=null,be--)}function Ce(e,t){be++,ye[be]=e.current,e.current=t}var Te=xe(null),Ee=xe(null),P=xe(null),De=xe(null);function F(e,t){switch(Ce(P,t),Ce(Ee,e),Ce(Te,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?Dp(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=Dp(t),e=Op(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}Se(Te),Ce(Te,e)}function Oe(){Se(Te),Se(Ee),Se(P)}function ke(e){var t=e.memoizedState;t!==null&&(Ch._currentValue=t.memoizedState,Ce(De,e)),t=Te.current;var n=Op(t,e.type);t!==n&&(Ce(Ee,e),Ce(Te,n))}function Ae(e){Ee.current===e&&(Se(Te),Se(Ee)),De.current===e&&(Se(De),Ch._currentValue=ve)}var je,Me;function Ne(e){if(je===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);je=t&&t[1]||``,Me=-1<e.stack.indexOf(`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ruby-CGfRnGY4.js","assets/html-Dkdzkf5m.js","assets/dist-DvRDAAjZ.js","assets/app.js","assets/javascript-qRALF4mN.js","assets/css-COynAVCS.js","assets/xml-Dg-qt816.js","assets/java-C0tX6Zjj.js","assets/sql-BJwLzEN3.js","assets/graphql-BUOosdAq.js","assets/typescript-dAcDzF3q.js","assets/cpp-M92QQ27h.js","assets/c-D2xwndn2.js","assets/shellscript-DugvE863.js","assets/lua-2gStHmQ-.js","assets/yaml-BOAQTz6b.js","assets/php-B4BGKN5F.js","assets/json-Hfsf52vC.js","assets/scss-DOxJ7xu_.js","assets/http-iVoGgZyc.js","assets/rst-DEFIrwXa.js","assets/html-derivative-B-zMOKjI.js","assets/python-_UfA4Rpn.js","assets/cmake-Cf85PuIk.js","assets/latex--YAwAQ5f.js","assets/r-vFiqf_wZ.js","assets/julia-CTkez5_b.js","assets/erlang-9UB0pWNm.js","assets/markdown-BR5vuK2p.js","assets/elixir-DIe8-kxb.js","assets/fsharp-CkcEwvkw.js","assets/perl-C6cfY4X6.js","assets/vue-b-L2NQfY.js","assets/svelte-Cnhqc3fy.js","assets/plugin-0Vwjcj6k.js","assets/WorkspacePanel.module-7fbly3iv.js","assets/WorkspacePanel.css","assets/plugin-q4wA1M0I.js","assets/plugin2.css","assets/plugin-Bn9YQlEA.js","assets/plugin.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
(function(){try{var e=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]=`91684640-d0ce-4379-99ba-b15e3717e7f1`,e._sentryDebugIdIdentifier=`sentry-dbid-91684640-d0ce-4379-99ba-b15e3717e7f1`)}catch{}})();import{_ as e,a as t,c as n,d as r,f as i,g as a,h as o,i as s,l as c,m as l,n as u,o as d,p as f,r as p,s as m,u as h,v as g}from"./dist-DvRDAAjZ.js";import{A as _,C as v,D as y,E as b,M as x,O as S,S as C,T as w,_ as T,a as E,b as D,c as O,d as k,f as ee,g as te,h as ne,i as A,j as re,k as ie,l as j,m as ae,n as oe,o as M,p as se,r as ce,s as le,t as ue,u as de,v as fe,w as pe,y as me}from"./WorkspacePanel.module-7fbly3iv.js";import{a as N,i as he,o as ge,r as _e,s as ve,t as ye}from"./app.js";import{t as be}from"./typescript-dAcDzF3q.js";import{t as xe}from"./shellscript-DugvE863.js";import{t as Se}from"./json-Hfsf52vC.js";var Ce=a((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&&te(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&&te(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,ee=k.port2;k.port1.onmessage=D,O=function(){ee.postMessage(null)}}else O=function(){_(D,0)};function te(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,te(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}}}})),we=a(((e,t)=>{t.exports=Ce()})),Te=a((e=>{var t=we(),n=o(),r=x();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 s(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 c(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 l(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 u(e){if(s(e)!==e)throw Error(i(188))}function d(e){var t=e.alternate;if(!t){if(t=s(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 o=a.alternate;if(o===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===o.child){for(o=a.child;o;){if(o===n)return u(a),e;if(o===r)return u(a),t;o=o.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=o;else{for(var c=!1,l=a.child;l;){if(l===n){c=!0,n=a,r=o;break}if(l===r){c=!0,r=a,n=o;break}l=l.sibling}if(!c){for(l=o.child;l;){if(l===n){c=!0,n=o,r=a;break}if(l===r){c=!0,r=o,n=a;break}l=l.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 p(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)&&p(e.child,t,n,r,i,a))return!0;e=e.sibling}return!1}function m(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 h(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 g(e){var t=[null,null],n=m(e);return n===null||_(t,e,n.child,{foundSelf:!1}),t}function _(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)&&_(e,t,n.child,r))return!0;n=n.sibling}return!1}function v(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 y=null,b=null;function S(e,t,n){return e===n||e===t&&(y=e,!0)}function C(e,t,n){return e===n?(b=e,!1):e===t&&(b!==null&&(y=e),!0)}function w(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 T(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 E=Object.assign,D=Symbol.for(`react.element`),O=Symbol.for(`react.transitional.element`),k=Symbol.for(`react.portal`),ee=Symbol.for(`react.fragment`),te=Symbol.for(`react.strict_mode`),ne=Symbol.for(`react.profiler`),A=Symbol.for(`react.consumer`),re=Symbol.for(`react.context`),ie=Symbol.for(`react.forward_ref`),j=Symbol.for(`react.suspense`),ae=Symbol.for(`react.suspense_list`),oe=Symbol.for(`react.memo`),M=Symbol.for(`react.lazy`),se=Symbol.for(`react.activity`),ce=Symbol.for(`react.legacy_hidden`),le=Symbol.for(`react.memo_cache_sentinel`),ue=Symbol.for(`react.view_transition`),de=Symbol.for(`react.recoverable`),fe=Symbol.iterator;function pe(e){return typeof e!=`object`||!e?null:(e=fe&&e[fe]||e[`@@iterator`],typeof e==`function`?e:null)}var me=Symbol.for(`react.client.reference`);function N(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===me?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case ee:return`Fragment`;case ne:return`Profiler`;case te:return`StrictMode`;case j:return`Suspense`;case ae:return`SuspenseList`;case se:return`Activity`;case ue:return`ViewTransition`}if(typeof e==`object`)switch(e.$$typeof){case k:return`Portal`;case re:return e.displayName||`Context`;case A:return(e._context.displayName||`Context`)+`.Consumer`;case ie:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case oe:return t=e.displayName||null,t===null?N(e.type)||`Memo`:t;case M:t=e._payload,e=e._init;try{return N(e(t))}catch{}}return null}var he=Array.isArray,ge=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,_e=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,ve={pending:!1,data:null,method:null,action:null},ye=[],be=-1;function xe(e){return{current:e}}function Se(e){0>be||(e.current=ye[be],ye[be]=null,be--)}function Ce(e,t){be++,ye[be]=e.current,e.current=t}var Te=xe(null),Ee=xe(null),P=xe(null),De=xe(null);function F(e,t){switch(Ce(P,t),Ce(Ee,e),Ce(Te,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?Dp(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=Dp(t),e=Op(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}Se(Te),Ce(Te,e)}function Oe(){Se(Te),Se(Ee),Se(P)}function ke(e){var t=e.memoizedState;t!==null&&(Ch._currentValue=t.memoizedState,Ce(De,e)),t=Te.current;var n=Op(t,e.type);t!==n&&(Ce(Ee,e),Ce(Te,n))}function Ae(e){Ee.current===e&&(Se(Te),Se(Ee)),De.current===e&&(Se(De),Ch._currentValue=ve)}var je,Me;function Ne(e){if(je===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);je=t&&t[1]||``,Me=-1<e.stack.indexOf(`
|
|
3
3
|
at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
|
|
4
4
|
`+je+e+Me}var Pe=!1;function Fe(e,t){if(!e||Pe)return``;Pe=!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(`
|
|
5
5
|
`),l=s.split(`
|
|
@@ -37,7 +37,7 @@ Error generating stack: `+e.message+`
|
|
|
37
37
|
`,inConstruct:`tableCell`},{atBreak:!0,character:`|`,after:`[ :-]`},{character:`|`,inConstruct:`tableCell`},{atBreak:!0,character:`:`,after:`-`},{atBreak:!0,character:`-`,after:`[:|-]`}],handlers:{inlineCode:f,table:o,tableCell:c,tableRow:s}};function o(e,t,n,r){return l(u(e,n,r),e.align)}function s(e,t,n,r){let i=l([d(e,n,r)]);return i.slice(0,i.indexOf(`
|
|
38
38
|
`))}function c(e,t,n,r){let i=n.enter(`tableCell`),o=n.enter(`phrasing`),s=n.containerPhrasing(e,{...r,before:a,after:a});return o(),i(),s}function l(e,t){return zl(e,{align:t,alignDelimiters:r,padding:n,stringLength:i})}function u(e,t,n){let r=e.children,i=-1,a=[],o=t.enter(`table`);for(;++i<r.length;)a[i]=d(r[i],t,n);return o(),a}function d(e,t,n){let r=e.children,i=-1,a=[],o=t.enter(`tableRow`);for(;++i<r.length;)a[i]=c(r[i],e,t,n);return o(),a}function f(e,t,n){let r=Ru.inlineCode(e,t,n);return n.stack.includes(`tableCell`)&&(r=r.replace(/\|/g,`\\$&`)),r}}function Ju(){return{exit:{taskListCheckValueChecked:Xu,taskListCheckValueUnchecked:Xu,paragraph:Zu}}}function Yu(){return{unsafe:[{atBreak:!0,character:`-`,after:`[:|-]`}],handlers:{listItem:Qu}}}function Xu(e){let t=this.stack[this.stack.length-2];t.type,t.checked=e.type===`taskListCheckValueChecked`}function Zu(e){let t=this.stack[this.stack.length-2];if(t&&t.type===`listItem`&&typeof t.checked==`boolean`){let e=this.stack[this.stack.length-1];e.type;let n=e.children[0];if(n&&n.type===`text`){let r=t.children,i=-1,a;for(;++i<r.length;){let e=r[i];if(e.type===`paragraph`){a=e;break}}a===e&&(n.value=n.value.slice(1),n.value.length===0?e.children.shift():e.position&&n.position&&typeof n.position.start.offset==`number`&&(n.position.start.column++,n.position.start.offset++,e.position.start=Object.assign({},n.position.start)))}}this.exit(e)}function Qu(e,t,n,r){let i=e.children[0],a=typeof e.checked==`boolean`&&i&&i.type===`paragraph`,o=`[`+(e.checked?`x`:` `)+`] `,s=n.createTracker(r);a&&s.move(o);let c=Ru.listItem(e,t,n,{...r,...s.current()});return a&&(c=c.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,l)),c;function l(e){return e+o}}function $u(){return[rl(),Dl(),Ml(),zu(),Ju()]}function ed(e){return{extensions:[il(),Ol(e),Nl(),qu(e),Yu()]}}var td={tokenize:hd,partial:!0},nd={tokenize:gd,partial:!0},rd={tokenize:_d,partial:!0},id={tokenize:vd,partial:!0},ad={tokenize:yd,partial:!0},od={name:`wwwAutolink`,tokenize:pd,previous:bd},sd={name:`protocolAutolink`,tokenize:md,previous:xd},cd={name:`emailAutolink`,tokenize:fd,previous:Sd},ld={};function ud(){return{text:ld}}for(var dd=48;dd<123;)ld[dd]=cd,dd++,dd===58?dd=65:dd===91&&(dd=97);ld[43]=cd,ld[45]=cd,ld[46]=cd,ld[95]=cd,ld[72]=[cd,sd],ld[104]=[cd,sd],ld[87]=[cd,od],ld[119]=[cd,od];function fd(e,t,n){let r=this,i,a;return o;function o(t){return!Cd(t)||!Sd.call(r,r.previous)||wd(r.events)?n(t):(e.enter(`literalAutolink`),e.enter(`literalAutolinkEmail`),s(t))}function s(t){return Cd(t)?(e.consume(t),s):t===64?(e.consume(t),c):n(t)}function c(t){return t===46?e.check(ad,u,l)(t):t===45||t===95||Qr(t)?(a=!0,e.consume(t),c):u(t)}function l(t){return e.consume(t),i=!0,c}function u(o){return a&&i&&Zr(r.previous)?(e.exit(`literalAutolinkEmail`),e.exit(`literalAutolink`),t(o)):n(o)}}function pd(e,t,n){let r=this;return i;function i(t){return t!==87&&t!==119||!bd.call(r,r.previous)||wd(r.events)?n(t):(e.enter(`literalAutolink`),e.enter(`literalAutolinkWww`),e.check(td,e.attempt(nd,e.attempt(rd,a),n),n)(t))}function a(n){return e.exit(`literalAutolinkWww`),e.exit(`literalAutolink`),t(n)}}function md(e,t,n){let r=this,i=``,a=!1;return o;function o(t){return(t===72||t===104)&&xd.call(r,r.previous)&&!wd(r.events)?(e.enter(`literalAutolink`),e.enter(`literalAutolinkHttp`),i+=String.fromCodePoint(t),e.consume(t),s):n(t)}function s(t){if(Zr(t)&&i.length<5)return i+=String.fromCodePoint(t),e.consume(t),s;if(t===58){let n=i.toLowerCase();if(n===`http`||n===`https`)return e.consume(t),c}return n(t)}function c(t){return t===47?(e.consume(t),a?l:(a=!0,c)):n(t)}function l(t){return t===null||ei(t)||ai(t)||ci(t)||si(t)?n(t):e.attempt(nd,e.attempt(rd,u),n)(t)}function u(n){return e.exit(`literalAutolinkHttp`),e.exit(`literalAutolink`),t(n)}}function hd(e,t,n){let r=0;return i;function i(t){return(t===87||t===119)&&r<3?(r++,e.consume(t),i):t===46&&r===3?(e.consume(t),a):n(t)}function a(e){return e===null?n(e):t(e)}}function gd(e,t,n){let r,i,a;return o;function o(t){return t===46||t===95?e.check(id,c,s)(t):t===null||ai(t)||ci(t)||t!==45&&si(t)?c(t):(a=!0,e.consume(t),o)}function s(t){return t===95?r=!0:(i=r,r=void 0),e.consume(t),o}function c(e){return i||r||!a?n(e):t(e)}}function _d(e,t){let n=0,r=0;return i;function i(o){return o===40?(n++,e.consume(o),i):o===41&&r<n?a(o):o===33||o===34||o===38||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===60||o===63||o===93||o===95||o===126?e.check(id,t,a)(o):o===null||ai(o)||ci(o)?t(o):(e.consume(o),i)}function a(t){return t===41&&r++,e.consume(t),i}}function vd(e,t,n){return r;function r(o){return o===33||o===34||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===63||o===95||o===126?(e.consume(o),r):o===38?(e.consume(o),a):o===93?(e.consume(o),i):o===60||o===null||ai(o)||ci(o)?t(o):n(o)}function i(e){return e===null||e===40||e===91||ai(e)||ci(e)?t(e):r(e)}function a(e){return Zr(e)?o(e):n(e)}function o(t){return t===59?(e.consume(t),r):Zr(t)?(e.consume(t),o):n(t)}}function yd(e,t,n){return r;function r(t){return e.consume(t),i}function i(e){return Qr(e)?n(e):t(e)}}function bd(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||ai(e)}function xd(e){return!Zr(e)}function Sd(e){return!(e===47||Cd(e))}function Cd(e){return e===43||e===45||e===46||e===95||Qr(e)}function wd(e){let t=e.length,n=!1;for(;t--;){let r=e[t][1];if((r.type===`labelLink`||r.type===`labelImage`)&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}var Td={tokenize:Nd,partial:!0};function Ed(){return{document:{91:{name:`gfmFootnoteDefinition`,tokenize:Ad,continuation:{tokenize:jd},exit:Md}},text:{91:{name:`gfmFootnoteCall`,tokenize:kd},93:{name:`gfmPotentialFootnoteCall`,add:`after`,tokenize:Dd,resolveTo:Od}}}}function Dd(e,t,n){let r=this,i=r.events.length,a=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),o;for(;i--;){let e=r.events[i][1];if(e.type===`labelImage`){o=e;break}if(e.type===`gfmFootnoteCall`||e.type===`labelLink`||e.type===`label`||e.type===`image`||e.type===`link`)break}return s;function s(i){if(!o||!o._balanced)return n(i);let s=Xr(r.sliceSerialize({start:o.end,end:r.now()}));return s.codePointAt(0)!==94||!a.includes(s.slice(1))?n(i):(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(i),e.exit(`gfmFootnoteCallLabelMarker`),t(i))}}function Od(e,t){let n=e.length;for(;n--;)if(e[n][1].type===`labelImage`&&e[n][0]===`enter`){e[n][1];break}e[n+1][1].type=`data`,e[n+3][1].type=`gfmFootnoteCallLabelMarker`;let r={type:`gfmFootnoteCall`,start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:`gfmFootnoteCallMarker`,start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;let a={type:`gfmFootnoteCallString`,start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},o={type:`chunkString`,contentType:`string`,start:Object.assign({},a.start),end:Object.assign({},a.end)},s=[e[n+1],e[n+2],[`enter`,r,t],e[n+3],e[n+4],[`enter`,i,t],[`exit`,i,t],[`enter`,a,t],[`enter`,o,t],[`exit`,o,t],[`exit`,a,t],e[e.length-2],e[e.length-1],[`exit`,r,t]];return e.splice(n,e.length-n+1,...s),e}function kd(e,t,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),a=0,o;return s;function s(t){return e.enter(`gfmFootnoteCall`),e.enter(`gfmFootnoteCallLabelMarker`),e.consume(t),e.exit(`gfmFootnoteCallLabelMarker`),c}function c(t){return t===94?(e.enter(`gfmFootnoteCallMarker`),e.consume(t),e.exit(`gfmFootnoteCallMarker`),e.enter(`gfmFootnoteCallString`),e.enter(`chunkString`).contentType=`string`,l):n(t)}function l(s){if(a>999||s===93&&!o||s===null||s===91||ai(s))return n(s);if(s===93){e.exit(`chunkString`);let a=e.exit(`gfmFootnoteCallString`);return i.includes(Xr(r.sliceSerialize(a)))?(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(s),e.exit(`gfmFootnoteCallLabelMarker`),e.exit(`gfmFootnoteCall`),t):n(s)}return ai(s)||(o=!0),a++,e.consume(s),s===92?u:l}function u(t){return t===91||t===92||t===93?(e.consume(t),a++,l):l(t)}}function Ad(e,t,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),a,o=0,s;return c;function c(t){return e.enter(`gfmFootnoteDefinition`)._container=!0,e.enter(`gfmFootnoteDefinitionLabel`),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),l}function l(t){return t===94?(e.enter(`gfmFootnoteDefinitionMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionMarker`),e.enter(`gfmFootnoteDefinitionLabelString`),e.enter(`chunkString`).contentType=`string`,u):n(t)}function u(t){if(o>999||t===93&&!s||t===null||t===91||ai(t))return n(t);if(t===93){e.exit(`chunkString`);let n=e.exit(`gfmFootnoteDefinitionLabelString`);return a=Xr(r.sliceSerialize(n)),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),e.exit(`gfmFootnoteDefinitionLabel`),f}return ai(t)||(s=!0),o++,e.consume(t),t===92?d:u}function d(t){return t===91||t===92||t===93?(e.consume(t),o++,u):u(t)}function f(t){return t===58?(e.enter(`definitionMarker`),e.consume(t),e.exit(`definitionMarker`),i.includes(a)||i.push(a),di(e,p,`gfmFootnoteDefinitionWhitespace`)):n(t)}function p(e){return t(e)}}function jd(e,t,n){return e.check(Di,t,e.attempt(Td,t,n))}function Md(e){e.exit(`gfmFootnoteDefinition`)}function Nd(e,t,n){let r=this;return di(e,i,`gfmFootnoteDefinitionIndent`,5);function i(e){let i=r.events[r.events.length-1];return i&&i[1].type===`gfmFootnoteDefinitionIndent`&&i[2].sliceSerialize(i[1],!0).length===4?t(e):n(e)}}function Pd(e){let t=(e||{}).singleTilde,n={name:`strikethrough`,tokenize:i,resolveAll:r};return t??=!0,{text:{126:n},insideSpan:{null:[n]},attentionMarkers:{null:[126]}};function r(e,t){let n=-1;for(;++n<e.length;)if(e[n][0]===`enter`&&e[n][1].type===`strikethroughSequenceTemporary`&&e[n][1]._close){let r=n;for(;r--;)if(e[r][0]===`exit`&&e[r][1].type===`strikethroughSequenceTemporary`&&e[r][1]._open&&e[n][1].end.offset-e[n][1].start.offset===e[r][1].end.offset-e[r][1].start.offset){e[n][1].type=`strikethroughSequence`,e[r][1].type=`strikethroughSequence`;let i={type:`strikethrough`,start:Object.assign({},e[r][1].start),end:Object.assign({},e[n][1].end)},a={type:`strikethroughText`,start:Object.assign({},e[r][1].end),end:Object.assign({},e[n][1].start)},o=[[`enter`,i,t],[`enter`,e[r][1],t],[`exit`,e[r][1],t],[`enter`,a,t]],s=t.parser.constructs.insideSpan.null;s&&Ur(o,o.length,0,bi(s,e.slice(r+1,n),t)),Ur(o,o.length,0,[[`exit`,a,t],[`enter`,e[n][1],t],[`exit`,e[n][1],t],[`exit`,i,t]]),Ur(e,r-1,n-r+3,o),n=r+o.length-2;break}}for(n=-1;++n<e.length;)e[n][1].type===`strikethroughSequenceTemporary`&&(e[n][1].type=`data`);return e}function i(e,n,r){let i=this.previous,a=this.events,o=0;return s;function s(t){return i===126&&a[a.length-1][1].type!==`characterEscape`?r(t):(e.enter(`strikethroughSequenceTemporary`),c(t))}function c(a){let s=yi(i);if(a===126)return o>1?r(a):(e.consume(a),o++,c);if(o<2&&!t)return r(a);let l=e.exit(`strikethroughSequenceTemporary`),u=yi(a);return l._open=!u||u===2&&!!s,l._close=!s||s===2&&!!u,n(a)}}}var Fd=class{constructor(){this.map=[],this.index=new Map}add(e,t,n){Id(this,e,t,n)}consume(e){if(this.map.sort(function(e,t){return e[0]-t[0]}),this.map.length===0)return;let t=this.map.length,n=[];for(;t>0;)--t,n.push(e.slice(this.map[t][0]+this.map[t][1]),this.map[t][2]),e.length=this.map[t][0];n.push(e.slice()),e.length=0;let r=n.pop();for(;r;){for(let t of r)e.push(t);r=n.pop()}this.map.length=0,this.index.clear()}};function Id(e,t,n,r){if(n===0&&r.length===0)return;let i=e.index.get(t);if(i){i[1]+=n,i[2].push(...r);return}let a=[t,n,r];e.map.push(a),e.index.set(t,a)}function Ld(e,t){let n=!1,r=[];for(;t<e.length;){let i=e[t];if(n){if(i[0]===`enter`)i[1].type===`tableContent`&&r.push(e[t+1][1].type===`tableDelimiterMarker`?`left`:`none`);else if(i[1].type===`tableContent`){if(e[t-1][1].type===`tableDelimiterMarker`){let e=r.length-1;r[e]=r[e]===`left`?`center`:`right`}}else if(i[1].type===`tableDelimiterRow`)break}else i[0]===`enter`&&i[1].type===`tableDelimiterRow`&&(n=!0);t+=1}return r}function Rd(){return{flow:{null:{name:`table`,tokenize:zd,resolveAll:Bd}}}}function zd(e,t,n){let r=this,i=0,a=0,o;return s;function s(e){let t=r.events.length-1;for(;t>-1;){let{type:e}=r.events[t][1];if(e===`lineEnding`||e===`linePrefix`)t--;else break}let i=t>-1?r.events[t][1].type:null,a=i===`tableHead`||i===`tableRow`?S:c;return a===S&&r.parser.lazy[r.now().line]?n(e):a(e)}function c(t){return e.enter(`tableHead`),e.enter(`tableRow`),l(t)}function l(e){return e===124||(o=!0,a+=1),u(e)}function u(t){return t===null?n(t):ii(t)?a>1?(a=0,r.interrupt=!0,e.exit(`tableRow`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),p):n(t):oi(t)?di(e,u,`whitespace`)(t):(a+=1,o&&(o=!1,i+=1),t===124?(e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),o=!0,u):(e.enter(`data`),d(t)))}function d(t){return t===null||t===124||ai(t)?(e.exit(`data`),u(t)):(e.consume(t),t===92?f:d)}function f(t){return t===92||t===124?(e.consume(t),d):d(t)}function p(t){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(t):(e.enter(`tableDelimiterRow`),o=!1,oi(t)?di(e,m,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):m(t))}function m(t){return t===45||t===58?g(t):t===124?(o=!0,e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),h):x(t)}function h(t){return oi(t)?di(e,g,`whitespace`)(t):g(t)}function g(t){return t===58?(a+=1,o=!0,e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),_):t===45?(a+=1,_(t)):t===null||ii(t)?b(t):x(t)}function _(t){return t===45?(e.enter(`tableDelimiterFiller`),v(t)):x(t)}function v(t){return t===45?(e.consume(t),v):t===58?(o=!0,e.exit(`tableDelimiterFiller`),e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),y):(e.exit(`tableDelimiterFiller`),y(t))}function y(t){return oi(t)?di(e,b,`whitespace`)(t):b(t)}function b(n){return n===124?m(n):n===null||ii(n)?!o||i!==a?x(n):(e.exit(`tableDelimiterRow`),e.exit(`tableHead`),t(n)):x(n)}function x(e){return n(e)}function S(t){return e.enter(`tableRow`),C(t)}function C(n){return n===124?(e.enter(`tableCellDivider`),e.consume(n),e.exit(`tableCellDivider`),C):n===null||ii(n)?(e.exit(`tableRow`),t(n)):oi(n)?di(e,C,`whitespace`)(n):(e.enter(`data`),w(n))}function w(t){return t===null||t===124||ai(t)?(e.exit(`data`),C(t)):(e.consume(t),t===92?T:w)}function T(t){return t===92||t===124?(e.consume(t),w):w(t)}}function Bd(e,t){let n=-1,r=!0,i=0,a=[0,0,0,0],o=[0,0,0,0],s=!1,c=0,l,u,d,f=new Fd;for(;++n<e.length;){let p=e[n],m=p[1];p[0]===`enter`?m.type===`tableHead`?(s=!1,c!==0&&(Hd(f,t,c,l,u),u=void 0,c=0),l={type:`table`,start:Object.assign({},m.start),end:Object.assign({},m.end)},f.add(n,0,[[`enter`,l,t]])):m.type===`tableRow`||m.type===`tableDelimiterRow`?(r=!0,d=void 0,a=[0,0,0,0],o=[0,n+1,0,0],s&&(s=!1,u={type:`tableBody`,start:Object.assign({},m.start),end:Object.assign({},m.end)},f.add(n,0,[[`enter`,u,t]])),i=m.type===`tableDelimiterRow`?2:u?3:1):i&&(m.type===`data`||m.type===`tableDelimiterMarker`||m.type===`tableDelimiterFiller`)?(r=!1,o[2]===0&&(a[1]!==0&&(o[0]=o[1],d=Vd(f,t,a,i,void 0,d),a=[0,0,0,0]),o[2]=n)):m.type===`tableCellDivider`&&(r?r=!1:(a[1]!==0&&(o[0]=o[1],d=Vd(f,t,a,i,void 0,d)),a=o,o=[a[1],n,0,0])):m.type===`tableHead`?(s=!0,c=n):m.type===`tableRow`||m.type===`tableDelimiterRow`?(c=n,a[1]===0?o[1]!==0&&(d=Vd(f,t,o,i,n,d)):(o[0]=o[1],d=Vd(f,t,a,i,n,d)),i=0):i&&(m.type===`data`||m.type===`tableDelimiterMarker`||m.type===`tableDelimiterFiller`)&&(o[3]=n)}for(c!==0&&Hd(f,t,c,l,u),f.consume(t.events),n=-1;++n<t.events.length;){let e=t.events[n];e[0]===`enter`&&e[1].type===`table`&&(e[1]._align=Ld(t.events,n))}return e}function Vd(e,t,n,r,i,a){let o=r===1?`tableHeader`:r===2?`tableDelimiter`:`tableData`;n[0]!==0&&(a.end=Object.assign({},Ud(t.events,n[0])),e.add(n[0],0,[[`exit`,a,t]]));let s=Ud(t.events,n[1]);if(a={type:o,start:Object.assign({},s),end:Object.assign({},s)},e.add(n[1],0,[[`enter`,a,t]]),n[2]!==0){let i=Ud(t.events,n[2]),a=Ud(t.events,n[3]),o={type:`tableContent`,start:Object.assign({},i),end:Object.assign({},a)};if(e.add(n[2],0,[[`enter`,o,t]]),r!==2){let r=t.events[n[2]],i=t.events[n[3]];if(r[1].end=Object.assign({},i[1].end),r[1].type=`chunkText`,r[1].contentType=`text`,n[3]>n[2]+1){let t=n[2]+1,r=n[3]-n[2]-1;e.add(t,r,[])}}e.add(n[3]+1,0,[[`exit`,o,t]])}return i!==void 0&&(a.end=Object.assign({},Ud(t.events,i)),e.add(i,0,[[`exit`,a,t]]),a=void 0),a}function Hd(e,t,n,r,i){let a=[],o=Ud(t.events,n);i&&(i.end=Object.assign({},o),a.push([`exit`,i,t])),r.end=Object.assign({},o),a.push([`exit`,r,t]),e.add(n+1,0,a)}function Ud(e,t){let n=e[t],r=n[0]===`enter`?`start`:`end`;return n[1][r]}var Wd={name:`tasklistCheck`,tokenize:Kd};function Gd(){return{text:{91:Wd}}}function Kd(e,t,n){let r=this;return i;function i(t){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(t):(e.enter(`taskListCheck`),e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),a)}function a(t){return ai(t)?(e.enter(`taskListCheckValueUnchecked`),e.consume(t),e.exit(`taskListCheckValueUnchecked`),o):t===88||t===120?(e.enter(`taskListCheckValueChecked`),e.consume(t),e.exit(`taskListCheckValueChecked`),o):n(t)}function o(t){return t===93?(e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),e.exit(`taskListCheck`),s):n(t)}function s(r){return ii(r)?t(r):oi(r)?e.check({tokenize:qd},t,n)(r):n(r)}}function qd(e,t,n){return di(e,r,`whitespace`);function r(e){return e===null?n(e):t(e)}}function Jd(e){return Kr([ud(),Ed(),Pd(e),Rd(),Gd()])}var Yd={};function Xd(e){let t=this,n=e||Yd,r=t.data(),i=r.micromarkExtensions||=[],a=r.fromMarkdownExtensions||=[],o=r.toMarkdownExtensions||=[];i.push(Jd(n)),a.push($u()),o.push(ed(n))}var Zd=(0,P.createContext)({});function Qd({children:e,openExternalLink:t,openFile:n,fileImages:r}){let i=(0,P.useMemo)(()=>({openExternalLink:t,openFile:n,fileImages:r}),[t,n,r]);return(0,F.jsx)(Zd.Provider,{value:i,children:e})}function $d(){return(0,P.useContext)(Zd)}function ef(e){let t=e.indexOf(`#`),n=t<0?e:e.slice(0,t);if(n.includes(`?`))return;let r;try{r=decodeURIComponent(n)}catch{return}if(r.length===0||/[\u0000-\u001f\u007f]/.test(r)||/^[\\/]{2}/.test(r)||/^[a-z][a-z\d+.-]*:/i.test(r)&&!/^[a-z]:[\\/]/i.test(r))return;if(t<0)return{path:r};let i=e.slice(t+1),a=/^L([1-9]\d*)(?:-L([1-9]\d*))?$/.exec(i);if(a===null)return;let o=Number(a[1]),s=a[2]===void 0?o:Number(a[2]);if(!(!Number.isSafeInteger(o)||!Number.isSafeInteger(s)||s<o))return{path:r,line:o}}async function tf(e){if(navigator.clipboard?.writeText)try{return await navigator.clipboard.writeText(e),!0}catch{}let t=typeof document.execCommand==`function`?document.execCommand.bind(document):void 0;if(t===void 0)return!1;let n=document.activeElement instanceof HTMLElement?document.activeElement:null,r=document.createElement(`textarea`);r.value=e,r.setAttribute(`readonly`,``),r.style.position=`fixed`,r.style.left=`-9999px`,document.body.appendChild(r),r.select();try{return t(`copy`)}catch{return!1}finally{r.remove(),n?.focus({preventScroll:!0})}}function nf({children:e}){let t=(0,P.useRef)(null),[n,i]=(0,P.useState)(!1);return(0,F.jsxs)(`div`,{className:`pi-code-block`,children:[(0,F.jsx)(`div`,{className:`pi-code-toolbar`,children:(0,F.jsx)(`button`,{type:`button`,onClick:async()=>{let e=await tf(t.current?.textContent??``);i(e),e&&window.setTimeout(()=>i(!1),1800)},children:n?r(`已复制`,`Copied`):r(`复制代码`,`Copy code`)})}),(0,F.jsx)(`pre`,{ref:t,children:e})]})}function rf({text:e}){let{openFile:t}=$d();return(0,F.jsx)(`div`,{className:`pi-markdown`,children:(0,F.jsx)(Wc,{remarkPlugins:[Xd],components:{pre:({children:e})=>(0,F.jsx)(nf,{children:e}),a:({href:e,children:n})=>{let r=e?ef(e):void 0,i=r!==void 0&&t!==void 0;return(0,F.jsx)(`a`,{href:e,target:i||e?.startsWith(`#`)?void 0:`_blank`,rel:`noopener noreferrer`,onClick:i?e=>{e.preventDefault(),t(r.path,r.line===void 0?void 0:{line:r.line})}:void 0,children:n})}},children:e})})}var af={root:`_root_rf6yg_9`,row:`_row_rf6yg_16`,leading:`_leading_rf6yg_29`,iconIdle:`_iconIdle_rf6yg_57`,chevronHover:`_chevronHover_rf6yg_63`,title:`_title_rf6yg_79`};function of({icon:e,title:t,open:n,onToggle:r,collapsedContent:i,children:a,rowClassName:o,leadingClassName:s,titleClassName:c,chevronClassName:l}){return(0,F.jsxs)(`div`,{className:af.root,"data-open":n||void 0,children:[(0,F.jsxs)(`div`,{className:`${af.row} ${o??``}`,"data-disclosure-row":!0,"data-expandable":!0,role:`button`,tabIndex:0,"aria-expanded":n,onClick:r,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),r())},children:[(0,F.jsx)(`span`,{className:`${af.leading} ${s??``}`,children:n?(0,F.jsx)(ct,{className:l}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`span`,{className:af.iconIdle,children:e}),(0,F.jsx)(ct,{className:`${af.chevronHover} ${l??``}`})]})}),(0,F.jsx)(`span`,{className:`${af.title} ${c??``}`,children:t}),!n&&i]}),n&&a]})}var sf={root:`_root_b8edg_1`,row:`_row_b8edg_11`,"piw-reasoning-row-sweep":`_piw-reasoning-row-sweep_b8edg_1`,leading:`_leading_b8edg_37`,chevron:`_chevron_b8edg_41`,title:`_title_b8edg_45`,separator:`_separator_b8edg_49`,summary:`_summary_b8edg_61`,summaryText:`_summaryText_b8edg_71`,thinkBody:`_thinkBody_b8edg_91`};function cf({text:e,running:t}){let[n,i]=(0,P.useState)(!1),a=e.trimEnd(),o=(t?a.slice(a.lastIndexOf(`
|
|
39
39
|
`)+1):e.split(`
|
|
40
|
-
`,1)[0]).replaceAll(`**`,``);return(0,F.jsx)(`div`,{className:sf.root,"data-variant":`think`,"data-state":t?`running`:`ok`,"data-expanded":n||void 0,children:(0,F.jsx)(of,{icon:(0,F.jsx)(mt,{size:14}),title:r(`思考`,`Thinking`),open:n,onToggle:()=>i(e=>!e),rowClassName:sf.row,leadingClassName:sf.leading,titleClassName:sf.title,chevronClassName:sf.chevron,collapsedContent:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`span`,{className:sf.separator,"aria-hidden":!0}),(0,F.jsx)(`span`,{className:sf.summary,"data-follow-end":t||void 0,children:(0,F.jsx)(`span`,{className:sf.summaryText,children:o})})]}),children:(0,F.jsx)(`div`,{className:sf.thinkBody,children:e})})})}function lf(e){let t=Math.max(0,Math.floor(e)),n=Math.floor(t/86400),r=Math.floor(t%86400/3600),i=Math.floor(t%3600/60),a=t%60;return n>0?`${n}d ${r}h ${i}m ${a}s`:r>0?`${r}h ${i}m ${a}s`:i>0?`${i}m ${a}s`:`${a}s`}var uf={root:`_root_1tps1_1`,icon:`_icon_1tps1_12`,"agent-activity-spin":`_agent-activity-spin_1tps1_1`,copy:`_copy_1tps1_19`};function df({state:e,elapsedSeconds:t}){return(0,F.jsxs)(`div`,{className:uf.root,"data-agent-activity":e,children:[(0,F.jsx)(`span`,{className:uf.icon,"aria-hidden":`true`,children:(0,F.jsx)(gt,{})}),(0,F.jsxs)(`span`,{className:`${tn.turnStatus} ${uf.copy}`,children:[(0,F.jsx)(`span`,{role:`status`,"aria-live":`polite`,"aria-atomic":`true`,children:e===`sending`?r(`正在发送`,`Sending`):r(`正在处理`,`Working`)}),(0,F.jsx)(`span`,{"data-agent-elapsed":t,"aria-hidden":`true`,children:` · ${lf(t)}`})]})]})}function ff(e,t,n,r){return!!e&&n===`connected`&&!e.interactions?.length&&!t?.error&&(r||!e.idle)}function pf(e,t,n,r){return!ff(e,t,n,r)||t?.blocks.some(e=>e.kind===`toolCall`||e.text.trim())?null:r?`sending`:`working`}function mf(e,t){let[n,r]=(0,P.useState)(null);return(0,P.useEffect)(()=>{if(!e){r(null);return}let n=performance.now();r({sessionId:t,seconds:0});let i=window.setInterval(()=>{r({sessionId:t,seconds:Math.max(0,Math.floor((performance.now()-n)/1e3))})},1e3);return()=>window.clearInterval(i)},[e,t]),e&&n&&n.sessionId===t?n.seconds:0}var hf=g(a(((e,t)=>{var n=[[{color:`0, 0, 0`,class:`ansi-black`},{color:`187, 0, 0`,class:`ansi-red`},{color:`0, 187, 0`,class:`ansi-green`},{color:`187, 187, 0`,class:`ansi-yellow`},{color:`0, 0, 187`,class:`ansi-blue`},{color:`187, 0, 187`,class:`ansi-magenta`},{color:`0, 187, 187`,class:`ansi-cyan`},{color:`255,255,255`,class:`ansi-white`}],[{color:`85, 85, 85`,class:`ansi-bright-black`},{color:`255, 85, 85`,class:`ansi-bright-red`},{color:`0, 255, 0`,class:`ansi-bright-green`},{color:`255, 255, 85`,class:`ansi-bright-yellow`},{color:`85, 85, 255`,class:`ansi-bright-blue`},{color:`255, 85, 255`,class:`ansi-bright-magenta`},{color:`85, 255, 255`,class:`ansi-bright-cyan`},{color:`255, 255, 255`,class:`ansi-bright-white`}]],r=/(https?:\/\/(?:[A-Za-z0-9#;/?:@=+$',_.!~*()[\]-]|&|%[A-Fa-f0-9]{2})+)/gm;t.exports=class e{static escapeForHtml(t){return new e().escapeForHtml(t)}static linkify(t){return new e().linkify(t)}static ansiToHtml(t,n){return new e().ansiToHtml(t,n)}static ansiToJson(t,n){return new e().ansiToJson(t,n)}static ansiToText(t){return new e().ansiToText(t)}constructor(){this.fg=this.bg=this.fg_truecolor=this.bg_truecolor=null,this.bright=0,this.decorations=[]}setupPalette(){this.PALETTE_COLORS=[];for(let e=0;e<2;++e)for(let t=0;t<8;++t)this.PALETTE_COLORS.push(n[e][t].color);let e=[0,95,135,175,215,255],t=(t,n,r)=>e[t]+`, `+e[n]+`, `+e[r];for(let e=0;e<6;++e)for(let n=0;n<6;++n)for(let r=0;r<6;++r)this.PALETTE_COLORS.push(t(e,n,r));let r=8;for(let e=0;e<24;++e,r+=10)this.PALETTE_COLORS.push(r+`, `+r+`, `+r)}escapeForHtml(e){return e.replace(/[&<>\"]/gm,e=>e==`&`?`&`:e==`"`?`"`:e==`<`?`<`:e==`>`?`>`:``)}linkify(e){return e.replace(r,e=>`<a href="${e}">${e}</a>`)}ansiToHtml(e,t){return this.process(e,t,!0)}ansiToJson(e,t){return t||={},t.json=!0,t.clearLine=!1,this.process(e,t,!0)}ansiToText(e){return this.process(e,{},!1)}process(e,t,n){let r=this,i=e.split(/\033\[/),a=i.shift();t??={},t.clearLine=/\r/.test(e);let o=i.map(e=>this.processChunk(e,t,n));if(t&&t.json){let e=r.processChunkJson(``);return e.content=a,e.clearLine=t.clearLine,o.unshift(e),t.remove_empty&&(o=o.filter(e=>!e.isEmpty())),o}return o.unshift(a),o.join(``)}processChunkJson(e,t,r){t=t===void 0?{}:t;let i=t.use_classes=t.use_classes!==void 0&&t.use_classes,a=t.key=i?`class`:`color`,o={content:e,fg:null,bg:null,fg_truecolor:null,bg_truecolor:null,isInverted:!1,clearLine:t.clearLine,decoration:null,decorations:[],was_processed:!1,isEmpty:()=>!o.content},s=e.match(/^([!\x3c-\x3f]*)([\d;]*)([\x20-\x2c]*[\x40-\x7e])([\s\S]*)/m);if(!s)return o;o.content=s[4];let c=s[2].split(`;`);if(s[1]!==``||s[3]!==`m`||!r)return o;let l=this;for(;c.length>0;){let e=c.shift(),t=parseInt(e);if(isNaN(t)||t===0)l.fg=l.bg=null,l.decorations=[];else if(t===1)l.decorations.push(`bold`);else if(t===2)l.decorations.push(`dim`);else if(t===3)l.decorations.push(`italic`);else if(t===4)l.decorations.push(`underline`);else if(t===5)l.decorations.push(`blink`);else if(t===7)l.decorations.push(`reverse`);else if(t===8)l.decorations.push(`hidden`);else if(t===9)l.decorations.push(`strikethrough`);else if(t===21)l.removeDecoration(`bold`);else if(t===22)l.removeDecoration(`bold`),l.removeDecoration(`dim`);else if(t===23)l.removeDecoration(`italic`);else if(t===24)l.removeDecoration(`underline`);else if(t===25)l.removeDecoration(`blink`);else if(t===27)l.removeDecoration(`reverse`);else if(t===28)l.removeDecoration(`hidden`);else if(t===29)l.removeDecoration(`strikethrough`);else if(t===39)l.fg=null;else if(t===49)l.bg=null;else if(t>=30&&t<38)l.fg=n[0][t%10][a];else if(t>=90&&t<98)l.fg=n[1][t%10][a];else if(t>=40&&t<48)l.bg=n[0][t%10][a];else if(t>=100&&t<108)l.bg=n[1][t%10][a];else if(t===38||t===48){let e=t===38;if(c.length>=1){let t=c.shift();if(t===`5`&&c.length>=1){let t=parseInt(c.shift());if(t>=0&&t<=255){if(!i)this.PALETTE_COLORS||l.setupPalette(),e?l.fg=this.PALETTE_COLORS[t]:l.bg=this.PALETTE_COLORS[t];else{let r=t>=16?`ansi-palette-`+t:n[+(t>7)][t%8].class;e?l.fg=r:l.bg=r}}}else if(t===`2`&&c.length>=3){let t=parseInt(c.shift()),n=parseInt(c.shift()),r=parseInt(c.shift());if(t>=0&&t<=255&&n>=0&&n<=255&&r>=0&&r<=255){let a=t+`, `+n+`, `+r;i?e?(l.fg=`ansi-truecolor`,l.fg_truecolor=a):(l.bg=`ansi-truecolor`,l.bg_truecolor=a):e?l.fg=a:l.bg=a}}}}}return l.fg===null&&l.bg===null&&l.decorations.length===0||(o.fg=l.fg,o.bg=l.bg,o.fg_truecolor=l.fg_truecolor,o.bg_truecolor=l.bg_truecolor,o.decorations=l.decorations,o.decoration=l.decorations.slice(-1).pop()||null,o.was_processed=!0),o}processChunk(e,t,r){t||={};let i=this.processChunkJson(e,t,r),a=t.use_classes;if(i.decorations=i.decorations.filter(e=>{if(e===`reverse`){i.fg||=n[0][7][a?`class`:`color`],i.bg||=n[0][0][a?`class`:`color`];let e=i.fg;i.fg=i.bg,i.bg=e;let t=i.fg_truecolor;return i.fg_truecolor=i.bg_truecolor,i.bg_truecolor=t,i.isInverted=!0,!1}return!0}),t.json)return i;if(i.isEmpty())return``;if(!i.was_processed)return i.content;let o=[],s=[],c=[],l={},u=e=>{let t=[],n;for(n in e)e.hasOwnProperty(n)&&t.push(`data-`+n+`="`+this.escapeForHtml(e[n])+`"`);return t.length>0?` `+t.join(` `):``};return i.isInverted&&(l[`ansi-is-inverted`]=`true`),i.fg&&(a?(o.push(i.fg+`-fg`),i.fg_truecolor!==null&&(l[`ansi-truecolor-fg`]=i.fg_truecolor,i.fg_truecolor=null)):o.push(`color:rgb(`+i.fg+`)`)),i.bg&&(a?(o.push(i.bg+`-bg`),i.bg_truecolor!==null&&(l[`ansi-truecolor-bg`]=i.bg_truecolor,i.bg_truecolor=null)):o.push(`background-color:rgb(`+i.bg+`)`)),i.decorations.forEach(e=>{a?s.push(`ansi-`+e):e===`bold`?s.push(`font-weight:bold`):e===`dim`?s.push(`opacity:0.5`):e===`italic`?s.push(`font-style:italic`):e===`hidden`?s.push(`visibility:hidden`):e===`strikethrough`?c.push(`line-through`):c.push(e)}),c.length&&s.push(`text-decoration:`+c.join(` `)),a?`<span class="`+o.concat(s).join(` `)+`"`+u(l)+`>`+i.content+`</span>`:`<span style="`+o.concat(s).join(`;`)+`"`+u(l)+`>`+i.content+`</span>`}removeDecoration(e){let t=this.decorations.indexOf(e);t>=0&&this.decorations.splice(t,1)}}}))(),1),gf={"0,0,0":`var(--dsw-alias-label-primary)`,"255,255,255":`var(--dsw-alias-label-primary)`,"85,85,85":`var(--dsw-alias-label-tertiary)`,"187,0,0":`var(--dsw-alias-state-error-primary)`,"255,85,85":`var(--dsw-alias-state-error-secondary)`,"0,187,0":`var(--dsw-alias-state-success-primary)`,"0,255,0":`var(--dsw-alias-state-success-secondary)`,"187,187,0":`var(--dsw-alias-state-warn-primary)`,"255,255,85":`var(--dsw-alias-state-warn-secondary)`,"0,0,187":`var(--dsw-alias-state-business-primary)`,"85,85,255":`var(--dsw-static-blue-400)`},_f={bold:{fontWeight:700},dim:{opacity:.7},italic:{fontStyle:`italic`},underline:{textDecoration:`underline`},strikethrough:{textDecoration:`line-through`},hidden:{visibility:`hidden`}},vf=/\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)?/g,yf=/\u001b(?!\[)[\u0020-\u002f]*[\u0030-\u007e]?/g,bf=/[\u0000-\u0007\u000b-\u001a\u001c-\u001f\u007f]/g,xf=/\r|\u0008|\u001b\[[\u0030-\u003f]*[\u0020-\u002f]*K/,Sf=/\u001b\[([\u0030-\u003f]*)[\u0020-\u002f]*m/g,Cf=8,wf=/^[\p{Mn}\p{Me}\p{Cf}\u200b-\u200f\u2060]$/u,Tf=RegExp(`\\p{Script=Han}|\\p{Script=Hiragana}|\\p{Script=Katakana}|\\p{Script=Hangul}|\\p{Emoji_Presentation}|[\\uff01-\\uff60\\u3000-\\u303e]`,`u`);function Ef(e){let t=e.codePointAt(0);return t===void 0||t<4352?!1:Tf.test(e)}var Df={fg:``,bg:``,attrs:[]},Of={22:[`1`,`2`],23:[`3`],24:[`4`],25:[`5`,`6`],27:[`7`],28:[`8`],29:[`9`]};function kf(e,t){let n=t===``?[`0`]:t.split(`;`),r=e;for(let e=0;e<n.length;e++){let t=String(n[e]);if(t===``||t===`0`){r=Df;continue}if(t===`38`||t===`48`){let i=n[e+1]??``,a=i===`2`?4:i===`5`?2:0,o=n.slice(e,e+a+1).join(`;`);r=t===`38`?{...r,fg:o}:{...r,bg:o},e+=a;continue}let i=Of[t];if(i!==void 0){r={...r,attrs:r.attrs.filter(e=>!i.includes(e))};continue}let a=Number(t);t===`39`?r={...r,fg:``}:t===`49`?r={...r,bg:``}:a>=30&&a<=37||a>=90&&a<=97?r={...r,fg:t}:a>=40&&a<=47||a>=100&&a<=107?r={...r,bg:t}:r.attrs.includes(t)||(r={...r,attrs:[...r.attrs,t]})}return r}function Af(e){let t=[...e.attrs];return e.fg!==``&&t.push(e.fg),e.bg!==``&&t.push(e.bg),t.length===0?``:`\u001b[${t.join(`;`)}m`}function jf(e,t){return e.fg===t.fg&&e.bg===t.bg&&e.attrs.length===t.attrs.length&&e.attrs.every((e,n)=>e===t.attrs[n])}function Mf(e,t){let n=/\u001b\[([\u0030-\u003f]*)[\u0020-\u002f]*([\u0040-\u007e])/g,r=[],i=0,a=t,o=0,s=(e,t)=>{let n=r[e];n?.spacer===!0&&e>0?r[e-1]={sgr:a,char:t}:n!==void 0&&Ef(n.char)&&r[e+1]?.spacer===!0&&(r[e+1]={sgr:a,char:t}),r[e]={sgr:a,char:t}},c=e=>{for(let t of e)if(t===`\r`)i=0;else if(t===`\b`)i=Math.max(0,i-1);else if(t===` `){let e=i+Cf-i%Cf;for(;i<e;i++)r[i]??={sgr:a,char:` `}}else if(wf.test(t)){let e=i>0?r[i-1]:void 0;e!==void 0&&(r[i-1]={sgr:e.sgr,char:e.char+t})}else s(i,` `),r[i]={sgr:a,char:t},i++,Ef(t)&&(r[i]={sgr:a,char:``,spacer:!0},i++)};for(let t of e.matchAll(n)){c(e.slice(o,t.index)),o=t.index+t[0].length;let n=String(t[1]),l=String(t[2]);if(l===`K`){let e=String(n.split(`;`)[0]);if(e===`1`)for(let e=0;e<=i;e++)s(e,` `);else r.length=e===`2`?0:i}else l===`m`&&(a=kf(a,n))}c(e.slice(o));let l=``,u=t;for(let e=0;e<r.length;e++){let t=r[e]??{sgr:Df,char:` `};jf(t.sgr,u)||(jf(u,Df)||(l+=`\x1B[0m`),l+=Af(t.sgr),u=t.sgr);let n=e>0&&Ef(r[e-1]?.char??``);l+=t.spacer===!0&&!n?` `:t.char}return jf(u,a)||(jf(u,Df)||(l+=`\x1B[0m`),l+=Af(a)),{text:l,sgr:a}}function Nf(e){let t=[],n=Df;for(let r of e.split(`
|
|
40
|
+
`,1)[0]).replaceAll(`**`,``);return(0,F.jsx)(`div`,{className:sf.root,"data-variant":`think`,"data-state":t?`running`:`ok`,"data-expanded":n||void 0,children:(0,F.jsx)(of,{icon:(0,F.jsx)(mt,{size:14}),title:r(`思考`,`Thinking`),open:n,onToggle:()=>i(e=>!e),rowClassName:sf.row,leadingClassName:sf.leading,titleClassName:sf.title,chevronClassName:sf.chevron,collapsedContent:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`span`,{className:sf.separator,"aria-hidden":!0}),(0,F.jsx)(`span`,{className:sf.summary,"data-follow-end":t||void 0,children:(0,F.jsx)(`span`,{className:sf.summaryText,children:o})})]}),children:(0,F.jsx)(`div`,{className:sf.thinkBody,children:e})})})}function lf(e){let t=Math.max(0,Math.floor(e)),n=Math.floor(t/86400),r=Math.floor(t%86400/3600),i=Math.floor(t%3600/60),a=t%60;return n>0?`${n}d ${r}h ${i}m ${a}s`:r>0?`${r}h ${i}m ${a}s`:i>0?`${i}m ${a}s`:`${a}s`}var uf={root:`_root_1tps1_1`,icon:`_icon_1tps1_12`,"agent-activity-spin":`_agent-activity-spin_1tps1_1`,copy:`_copy_1tps1_19`};function df({state:e,elapsedSeconds:t}){return(0,F.jsxs)(`div`,{className:uf.root,"data-agent-activity":e,children:[(0,F.jsx)(`span`,{className:uf.icon,"aria-hidden":`true`,children:(0,F.jsx)(gt,{})}),(0,F.jsxs)(`span`,{className:`${tn.turnStatus} ${uf.copy}`,children:[(0,F.jsx)(`span`,{role:`status`,"aria-live":`polite`,"aria-atomic":`true`,children:e===`sending`?r(`正在发送`,`Sending`):r(`正在处理`,`Working`)}),(0,F.jsx)(`span`,{"data-agent-elapsed":t,"aria-hidden":`true`,children:` · ${lf(t)}`})]})]})}function ff(e,t,n,r){return!!e&&n===`connected`&&!e.interactions?.length&&!t?.error&&(r||!e.idle)}function pf(e,t,n,r){return!ff(e,t,n,r)||t?.blocks.some(e=>e.kind===`toolCall`||e.text.trim())?null:r?`sending`:`working`}function mf(e,t,n=0){let r=(0,P.useRef)(new Map),[i,a]=(0,P.useState)(null);return(0,P.useEffect)(()=>{if(!e||!t){t&&r.current.delete(t),a(null);return}let i=r.current.get(t),o=i?.activityId===n?i.started:performance.now();i?.activityId!==n&&r.current.set(t,{activityId:n,started:o});let s=()=>a({sessionId:t,activityId:n,seconds:Math.max(0,Math.floor((performance.now()-o)/1e3))});s();let c=window.setInterval(s,1e3);return()=>window.clearInterval(c)},[e,t,n]),e&&i&&i.sessionId===t&&i.activityId===n?i.seconds:0}var hf=g(a(((e,t)=>{var n=[[{color:`0, 0, 0`,class:`ansi-black`},{color:`187, 0, 0`,class:`ansi-red`},{color:`0, 187, 0`,class:`ansi-green`},{color:`187, 187, 0`,class:`ansi-yellow`},{color:`0, 0, 187`,class:`ansi-blue`},{color:`187, 0, 187`,class:`ansi-magenta`},{color:`0, 187, 187`,class:`ansi-cyan`},{color:`255,255,255`,class:`ansi-white`}],[{color:`85, 85, 85`,class:`ansi-bright-black`},{color:`255, 85, 85`,class:`ansi-bright-red`},{color:`0, 255, 0`,class:`ansi-bright-green`},{color:`255, 255, 85`,class:`ansi-bright-yellow`},{color:`85, 85, 255`,class:`ansi-bright-blue`},{color:`255, 85, 255`,class:`ansi-bright-magenta`},{color:`85, 255, 255`,class:`ansi-bright-cyan`},{color:`255, 255, 255`,class:`ansi-bright-white`}]],r=/(https?:\/\/(?:[A-Za-z0-9#;/?:@=+$',_.!~*()[\]-]|&|%[A-Fa-f0-9]{2})+)/gm;t.exports=class e{static escapeForHtml(t){return new e().escapeForHtml(t)}static linkify(t){return new e().linkify(t)}static ansiToHtml(t,n){return new e().ansiToHtml(t,n)}static ansiToJson(t,n){return new e().ansiToJson(t,n)}static ansiToText(t){return new e().ansiToText(t)}constructor(){this.fg=this.bg=this.fg_truecolor=this.bg_truecolor=null,this.bright=0,this.decorations=[]}setupPalette(){this.PALETTE_COLORS=[];for(let e=0;e<2;++e)for(let t=0;t<8;++t)this.PALETTE_COLORS.push(n[e][t].color);let e=[0,95,135,175,215,255],t=(t,n,r)=>e[t]+`, `+e[n]+`, `+e[r];for(let e=0;e<6;++e)for(let n=0;n<6;++n)for(let r=0;r<6;++r)this.PALETTE_COLORS.push(t(e,n,r));let r=8;for(let e=0;e<24;++e,r+=10)this.PALETTE_COLORS.push(r+`, `+r+`, `+r)}escapeForHtml(e){return e.replace(/[&<>\"]/gm,e=>e==`&`?`&`:e==`"`?`"`:e==`<`?`<`:e==`>`?`>`:``)}linkify(e){return e.replace(r,e=>`<a href="${e}">${e}</a>`)}ansiToHtml(e,t){return this.process(e,t,!0)}ansiToJson(e,t){return t||={},t.json=!0,t.clearLine=!1,this.process(e,t,!0)}ansiToText(e){return this.process(e,{},!1)}process(e,t,n){let r=this,i=e.split(/\033\[/),a=i.shift();t??={},t.clearLine=/\r/.test(e);let o=i.map(e=>this.processChunk(e,t,n));if(t&&t.json){let e=r.processChunkJson(``);return e.content=a,e.clearLine=t.clearLine,o.unshift(e),t.remove_empty&&(o=o.filter(e=>!e.isEmpty())),o}return o.unshift(a),o.join(``)}processChunkJson(e,t,r){t=t===void 0?{}:t;let i=t.use_classes=t.use_classes!==void 0&&t.use_classes,a=t.key=i?`class`:`color`,o={content:e,fg:null,bg:null,fg_truecolor:null,bg_truecolor:null,isInverted:!1,clearLine:t.clearLine,decoration:null,decorations:[],was_processed:!1,isEmpty:()=>!o.content},s=e.match(/^([!\x3c-\x3f]*)([\d;]*)([\x20-\x2c]*[\x40-\x7e])([\s\S]*)/m);if(!s)return o;o.content=s[4];let c=s[2].split(`;`);if(s[1]!==``||s[3]!==`m`||!r)return o;let l=this;for(;c.length>0;){let e=c.shift(),t=parseInt(e);if(isNaN(t)||t===0)l.fg=l.bg=null,l.decorations=[];else if(t===1)l.decorations.push(`bold`);else if(t===2)l.decorations.push(`dim`);else if(t===3)l.decorations.push(`italic`);else if(t===4)l.decorations.push(`underline`);else if(t===5)l.decorations.push(`blink`);else if(t===7)l.decorations.push(`reverse`);else if(t===8)l.decorations.push(`hidden`);else if(t===9)l.decorations.push(`strikethrough`);else if(t===21)l.removeDecoration(`bold`);else if(t===22)l.removeDecoration(`bold`),l.removeDecoration(`dim`);else if(t===23)l.removeDecoration(`italic`);else if(t===24)l.removeDecoration(`underline`);else if(t===25)l.removeDecoration(`blink`);else if(t===27)l.removeDecoration(`reverse`);else if(t===28)l.removeDecoration(`hidden`);else if(t===29)l.removeDecoration(`strikethrough`);else if(t===39)l.fg=null;else if(t===49)l.bg=null;else if(t>=30&&t<38)l.fg=n[0][t%10][a];else if(t>=90&&t<98)l.fg=n[1][t%10][a];else if(t>=40&&t<48)l.bg=n[0][t%10][a];else if(t>=100&&t<108)l.bg=n[1][t%10][a];else if(t===38||t===48){let e=t===38;if(c.length>=1){let t=c.shift();if(t===`5`&&c.length>=1){let t=parseInt(c.shift());if(t>=0&&t<=255){if(!i)this.PALETTE_COLORS||l.setupPalette(),e?l.fg=this.PALETTE_COLORS[t]:l.bg=this.PALETTE_COLORS[t];else{let r=t>=16?`ansi-palette-`+t:n[+(t>7)][t%8].class;e?l.fg=r:l.bg=r}}}else if(t===`2`&&c.length>=3){let t=parseInt(c.shift()),n=parseInt(c.shift()),r=parseInt(c.shift());if(t>=0&&t<=255&&n>=0&&n<=255&&r>=0&&r<=255){let a=t+`, `+n+`, `+r;i?e?(l.fg=`ansi-truecolor`,l.fg_truecolor=a):(l.bg=`ansi-truecolor`,l.bg_truecolor=a):e?l.fg=a:l.bg=a}}}}}return l.fg===null&&l.bg===null&&l.decorations.length===0||(o.fg=l.fg,o.bg=l.bg,o.fg_truecolor=l.fg_truecolor,o.bg_truecolor=l.bg_truecolor,o.decorations=l.decorations,o.decoration=l.decorations.slice(-1).pop()||null,o.was_processed=!0),o}processChunk(e,t,r){t||={};let i=this.processChunkJson(e,t,r),a=t.use_classes;if(i.decorations=i.decorations.filter(e=>{if(e===`reverse`){i.fg||=n[0][7][a?`class`:`color`],i.bg||=n[0][0][a?`class`:`color`];let e=i.fg;i.fg=i.bg,i.bg=e;let t=i.fg_truecolor;return i.fg_truecolor=i.bg_truecolor,i.bg_truecolor=t,i.isInverted=!0,!1}return!0}),t.json)return i;if(i.isEmpty())return``;if(!i.was_processed)return i.content;let o=[],s=[],c=[],l={},u=e=>{let t=[],n;for(n in e)e.hasOwnProperty(n)&&t.push(`data-`+n+`="`+this.escapeForHtml(e[n])+`"`);return t.length>0?` `+t.join(` `):``};return i.isInverted&&(l[`ansi-is-inverted`]=`true`),i.fg&&(a?(o.push(i.fg+`-fg`),i.fg_truecolor!==null&&(l[`ansi-truecolor-fg`]=i.fg_truecolor,i.fg_truecolor=null)):o.push(`color:rgb(`+i.fg+`)`)),i.bg&&(a?(o.push(i.bg+`-bg`),i.bg_truecolor!==null&&(l[`ansi-truecolor-bg`]=i.bg_truecolor,i.bg_truecolor=null)):o.push(`background-color:rgb(`+i.bg+`)`)),i.decorations.forEach(e=>{a?s.push(`ansi-`+e):e===`bold`?s.push(`font-weight:bold`):e===`dim`?s.push(`opacity:0.5`):e===`italic`?s.push(`font-style:italic`):e===`hidden`?s.push(`visibility:hidden`):e===`strikethrough`?c.push(`line-through`):c.push(e)}),c.length&&s.push(`text-decoration:`+c.join(` `)),a?`<span class="`+o.concat(s).join(` `)+`"`+u(l)+`>`+i.content+`</span>`:`<span style="`+o.concat(s).join(`;`)+`"`+u(l)+`>`+i.content+`</span>`}removeDecoration(e){let t=this.decorations.indexOf(e);t>=0&&this.decorations.splice(t,1)}}}))(),1),gf={"0,0,0":`var(--dsw-alias-label-primary)`,"255,255,255":`var(--dsw-alias-label-primary)`,"85,85,85":`var(--dsw-alias-label-tertiary)`,"187,0,0":`var(--dsw-alias-state-error-primary)`,"255,85,85":`var(--dsw-alias-state-error-secondary)`,"0,187,0":`var(--dsw-alias-state-success-primary)`,"0,255,0":`var(--dsw-alias-state-success-secondary)`,"187,187,0":`var(--dsw-alias-state-warn-primary)`,"255,255,85":`var(--dsw-alias-state-warn-secondary)`,"0,0,187":`var(--dsw-alias-state-business-primary)`,"85,85,255":`var(--dsw-static-blue-400)`},_f={bold:{fontWeight:700},dim:{opacity:.7},italic:{fontStyle:`italic`},underline:{textDecoration:`underline`},strikethrough:{textDecoration:`line-through`},hidden:{visibility:`hidden`}},vf=/\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)?/g,yf=/\u001b(?!\[)[\u0020-\u002f]*[\u0030-\u007e]?/g,bf=/[\u0000-\u0007\u000b-\u001a\u001c-\u001f\u007f]/g,xf=/\r|\u0008|\u001b\[[\u0030-\u003f]*[\u0020-\u002f]*K/,Sf=/\u001b\[([\u0030-\u003f]*)[\u0020-\u002f]*m/g,Cf=8,wf=/^[\p{Mn}\p{Me}\p{Cf}\u200b-\u200f\u2060]$/u,Tf=RegExp(`\\p{Script=Han}|\\p{Script=Hiragana}|\\p{Script=Katakana}|\\p{Script=Hangul}|\\p{Emoji_Presentation}|[\\uff01-\\uff60\\u3000-\\u303e]`,`u`);function Ef(e){let t=e.codePointAt(0);return t===void 0||t<4352?!1:Tf.test(e)}var Df={fg:``,bg:``,attrs:[]},Of={22:[`1`,`2`],23:[`3`],24:[`4`],25:[`5`,`6`],27:[`7`],28:[`8`],29:[`9`]};function kf(e,t){let n=t===``?[`0`]:t.split(`;`),r=e;for(let e=0;e<n.length;e++){let t=String(n[e]);if(t===``||t===`0`){r=Df;continue}if(t===`38`||t===`48`){let i=n[e+1]??``,a=i===`2`?4:i===`5`?2:0,o=n.slice(e,e+a+1).join(`;`);r=t===`38`?{...r,fg:o}:{...r,bg:o},e+=a;continue}let i=Of[t];if(i!==void 0){r={...r,attrs:r.attrs.filter(e=>!i.includes(e))};continue}let a=Number(t);t===`39`?r={...r,fg:``}:t===`49`?r={...r,bg:``}:a>=30&&a<=37||a>=90&&a<=97?r={...r,fg:t}:a>=40&&a<=47||a>=100&&a<=107?r={...r,bg:t}:r.attrs.includes(t)||(r={...r,attrs:[...r.attrs,t]})}return r}function Af(e){let t=[...e.attrs];return e.fg!==``&&t.push(e.fg),e.bg!==``&&t.push(e.bg),t.length===0?``:`\u001b[${t.join(`;`)}m`}function jf(e,t){return e.fg===t.fg&&e.bg===t.bg&&e.attrs.length===t.attrs.length&&e.attrs.every((e,n)=>e===t.attrs[n])}function Mf(e,t){let n=/\u001b\[([\u0030-\u003f]*)[\u0020-\u002f]*([\u0040-\u007e])/g,r=[],i=0,a=t,o=0,s=(e,t)=>{let n=r[e];n?.spacer===!0&&e>0?r[e-1]={sgr:a,char:t}:n!==void 0&&Ef(n.char)&&r[e+1]?.spacer===!0&&(r[e+1]={sgr:a,char:t}),r[e]={sgr:a,char:t}},c=e=>{for(let t of e)if(t===`\r`)i=0;else if(t===`\b`)i=Math.max(0,i-1);else if(t===` `){let e=i+Cf-i%Cf;for(;i<e;i++)r[i]??={sgr:a,char:` `}}else if(wf.test(t)){let e=i>0?r[i-1]:void 0;e!==void 0&&(r[i-1]={sgr:e.sgr,char:e.char+t})}else s(i,` `),r[i]={sgr:a,char:t},i++,Ef(t)&&(r[i]={sgr:a,char:``,spacer:!0},i++)};for(let t of e.matchAll(n)){c(e.slice(o,t.index)),o=t.index+t[0].length;let n=String(t[1]),l=String(t[2]);if(l===`K`){let e=String(n.split(`;`)[0]);if(e===`1`)for(let e=0;e<=i;e++)s(e,` `);else r.length=e===`2`?0:i}else l===`m`&&(a=kf(a,n))}c(e.slice(o));let l=``,u=t;for(let e=0;e<r.length;e++){let t=r[e]??{sgr:Df,char:` `};jf(t.sgr,u)||(jf(u,Df)||(l+=`\x1B[0m`),l+=Af(t.sgr),u=t.sgr);let n=e>0&&Ef(r[e-1]?.char??``);l+=t.spacer===!0&&!n?` `:t.char}return jf(u,a)||(jf(u,Df)||(l+=`\x1B[0m`),l+=Af(a)),{text:l,sgr:a}}function Nf(e){let t=[],n=Df;for(let r of e.split(`
|
|
41
41
|
`)){let e=r.replace(/\r+$/,``);if(xf.test(e)){let r=Mf(e,n);t.push(r.text),n=r.sgr}else{t.push(e);for(let t of e.matchAll(Sf))n=kf(n,String(t[1]))}}return t.join(`
|
|
42
42
|
`)}function Pf(e){return Nf(e.replace(vf,``).replace(yf,``)).replace(bf,``)}function Ff(e){let t={},n=e.bg===null?void 0:`rgb(${e.bg})`;if(n!==void 0&&(t.backgroundColor=n),e.fg!==null){let r=`rgb(${e.fg})`;t.color=n===void 0?gf[e.fg.replace(/\s+/g,``)]??r:r}for(let n of e.decorations)Object.assign(t,_f[n]);return Object.keys(t).length===0?void 0:t}function If(e){let t=[],n=[t];for(let r of hf.default.ansiToJson(Pf(e),{json:!0,remove_empty:!0})){let e=Ff(r);for(let[i,a]of r.content.split(`
|
|
43
43
|
`).entries())i>0&&(t=[],n.push(t)),a!==``&&t.push({text:a,style:e})}return n}function Lf(e,t,n){let r=e-t,i=Math.ceil(t/2);return{hidden:r,capped:r>0&&!n,headLines:i,tailLines:t-i}}var Rf=1e3;function zf(e){let[t,n]=(0,P.useState)(!1);return{copied:t,onCopy:(0,P.useCallback)(()=>{t||tf(e).then(e=>{e&&(n(!0),window.setTimeout(()=>{n(!1)},Rf))})},[t,e])}}var Bf={pill:`_pill_e3ygd_1`,interactive:`_interactive_e3ygd_15`,active:`_active_e3ygd_23`};function Vf({active:e=!1,className:t,children:r,onClick:i,...a}){return i?(0,F.jsx)(`button`,{type:`button`,className:n(Bf.pill,Bf.interactive,e&&Bf.active,t),onClick:i,...a,children:r}):(0,F.jsx)(`span`,{className:n(Bf.pill,e&&Bf.active,t),children:r})}var Hf={block:`_block_1gdtu_1`,header:`_header_1gdtu_32`,prompt:`_prompt_1gdtu_70`,promptLine:`_promptLine_1gdtu_78`,runState:`_runState_1gdtu_91`,runStateLabel:`_runStateLabel_1gdtu_99`,cwd:`_cwd_1gdtu_108`,command:`_command_1gdtu_116`,status:`_status_1gdtu_128`,copyButton:`_copyButton_1gdtu_136`,output:`_output_1gdtu_156`,line:`_line_1gdtu_180`,expand:`_expand_1gdtu_185`,empty:`_empty_1gdtu_201`};function Uf(e,t){let n=e.replace(/[/\\]+$/,``);if(t!==void 0&&n===t.replace(/[/\\]+$/,``))return`~`;let r=n.split(/[/\\]/).pop();return r===void 0||r===``?e:r}function Wf(e,t,n){if(t!==void 0)return n.signal(t);if(e!==void 0&&e!==0)return n.exitCode(e)}function Gf(e,t,n,r){return e?{state:`ongoing`,label:r.running}:Wf(t,n,r)===void 0?{state:`done`,label:r.done}:{state:`error`,label:r.failed}}function Kf(e){return e.map((e,t)=>e.style===void 0?e.text:(0,F.jsx)(`span`,{style:e.style,children:e.text},t))}function qf({command:e,cwd:t,home:r,output:i,exitCode:a,signal:o,running:s=!1,maxLines:c=16,className:l,labels:u}){let d=u,f=i??``,p=(0,P.useMemo)(()=>{let e=If(f),t=e[e.length-1];return e.length>1&&t!==void 0&&t.every(e=>e.text===``)?e.slice(0,-1):e},[f]),[m,h]=(0,P.useState)(!1),{copied:g,onCopy:_}=zf(f),v=(0,P.useCallback)(()=>{h(e=>!e)},[]),y=Wf(a,o,d),b=Gf(s,a,o,d),x=(0,P.useMemo)(()=>(e.endsWith(`
|
|
@@ -58,7 +58,7 @@ Error generating stack: `+e.message+`
|
|
|
58
58
|
`).entries())t&&i.append(mS()),n&&i.append(Iv(n));t.clear().append(i),n&&i.selectEnd()},{discrete:!0}),e.value||r.dispatchCommand(sh,void 0))},[r,e.value]),(0,P.useLayoutEffect)(()=>{RD(r)},[r,e.claimToken]),(0,F.jsx)(`div`,{className:en.scroll,"data-input-scroll":!0,children:(0,F.jsxs)(`div`,{className:en.grow,children:[(0,F.jsx)(PD,{editor:r,editable:e.editable,className:en.input,"aria-label":e.ariaLabel,"aria-disabled":!e.editable||void 0,"aria-haspopup":`listbox`,"aria-expanded":e.menuOpen,"aria-activedescendant":e.activeOption,"data-phase":e.claimToken?`claimed`:`plain`,"data-placeholder":e.placeholder,"data-composer-composing":i||void 0,style:e.hint===null?void 0:{"--dsh-composer-hint":JSON.stringify(e.hint)},onKeyDownCapture:t=>{e.onKeyDown(t),t.defaultPrevented&&t.stopPropagation()},onPasteCapture:t=>{e.onPaste(t),t.defaultPrevented&&t.stopPropagation()},onCompositionStart:()=>a(!0),onCompositionEnd:()=>a(!1)}),e.value===``&&(0,F.jsx)(`div`,{"aria-hidden":!0,className:en.placeholder,"data-composer-placeholder":!0,children:e.placeholder})]})})});function BD(e,t){return typeof e==`string`?e:e?.[t]}function VD(e,t,n,r){let i=new Map;for(let n of[...e,...t.map(e=>({...e,section:`commands`}))])i.has(n.name)||i.set(n.name,{...n,section:n.section??`commands`});for(let e of n){for(let t of e.definition.commands??[])i.set(t.id,{name:t.id,label:BD(t.presentation?.label,r)??t.title,description:BD(t.presentation?.description,r)??t.description,icon:t.presentation?.icon,section:t.presentation?.section??`commands`,input:t.input,pluginId:e.id,action:t.action});for(let t of e.definition.menuItems??[])t.menu===`composer`&&i.set(`${e.id}:${t.id}`,{name:t.title,label:t.title,section:`add`,pluginId:e.id,action:t.action,menuOnly:!0})}return[...i.values()].sort((e,t)=>Number(t.section===`add`)-Number(e.section===`add`))}function HD(e){let t=e.input?.token;return[e.name,...typeof t==`string`?[t]:t?[t.zh,t.en]:[]]}function UD(e,t){let n=/^\/(\S+)(?:\s([\s\S]*))?$/.exec(e.trimStart());if(!n)return;let r=t.find(e=>!e.menuOnly&&e.name===n[1])??t.find(e=>!e.menuOnly&&HD(e).includes(n[1]));return r?{command:r,token:`/${n[1]}`,text:(n[2]??``).trim()}:void 0}function WD(e,t,n){let r=t.toLocaleLowerCase();return e.filter(e=>(!n||!e.menuOnly)&&[...HD(e),e.label??``].some(e=>e.toLocaleLowerCase().includes(r)))}function GD(e,t,n,r,i){if(!(!t||t.idle&&(r.trim()||i))){for(let r of e){let e=r.definition.composerAction?.(t,n);if(!(!e||(t.idle?e.kind!==`invoke`:e.kind!==`stop`)))return{...e,pluginId:r.id,sessionId:t.sessionId}}if(!t.idle)return{kind:`stop`,sessionId:t.sessionId,label:n===`zh`?`暂停执行`:`Pause`,title:n===`zh`?`暂停当前执行,保留已有进度`:`Pause execution and keep existing progress`};if(t.paused)return{kind:`resume`,sessionId:t.sessionId,label:n===`zh`?`继续执行`:`Continue`,title:n===`zh`?`基于已有进度继续执行`:`Continue from existing progress`}}}async function KD(e,t,n,r,i,a){if(i()!==e.sessionId)throw Error(`Session changed`);if(e.kind===`stop`)return r();if(e.kind===`resume`){if(!a)throw Error(`Resume is unavailable`);return a()}if(!e.pluginId)throw Error(`Missing plugin for composer action`);let o=await t(e.pluginId,e.action,e.input);if(i()!==e.sessionId)throw Error(`Session changed`);if(!e.sendResultMessage)return;let s=o?.message;if(typeof s!=`string`||!s.trim())throw Error(`Plugin action did not return a message`);await n(s)}var qD=12;function JD(e,t,n){let[r,i]=(0,P.useState)(t);return(0,P.useLayoutEffect)(()=>{let n=e.current;if(n===null)return;let r=()=>{i(Math.min(t,Math.max(0,n.getBoundingClientRect().bottom-qD)))};return r(),window.addEventListener(`resize`,r),window.addEventListener(`scroll`,r,!0),()=>{window.removeEventListener(`resize`,r),window.removeEventListener(`scroll`,r,!0)}},[e,t,n]),r}var YD={menu:`_menu_1lxmu_1`,viewport:`_viewport_1lxmu_44`,item:`_item_1lxmu_51`,active:`_active_1lxmu_70`,sectionTitle:`_sectionTitle_1lxmu_74`,itemIcon:`_itemIcon_1lxmu_88`,itemName:`_itemName_1lxmu_103`,itemAlias:`_itemAlias_1lxmu_113`,itemDescription:`_itemDescription_1lxmu_126`,trailing:`_trailing_1lxmu_140`,drillHintText:`_drillHintText_1lxmu_151`,drillHint:`_drillHint_1lxmu_151`,drill:`_drill_1lxmu_151`,groupTitle:`_groupTitle_1lxmu_194`,skeletonRow:`_skeletonRow_1lxmu_204`,skeletonBar:`_skeletonBar_1lxmu_213`,"dsh-menu-skeleton":`_dsh-menu-skeleton_1lxmu_1`,crumbs:`_crumbs_1lxmu_229`,crumb:`_crumb_1lxmu_229`,crumbCurrent:`_crumbCurrent_1lxmu_264`,crumbSeparator:`_crumbSeparator_1lxmu_270`};function XD(){return[{name:`file`,label:r(`文件`,`File`),section:`add`,icon:T,menuOnly:!1},{name:`compact`,label:r(`压缩`,`Compact`),icon:j,description:r(`压缩当前会话内容`,`Compact the current session`)},{name:`model`,label:r(`模型`,`Model`),icon:k,description:r(`选择本会话使用的模型`,`Choose the model for this session`)},{name:`new`,label:r(`新会话`,`New session`),icon:ae,description:r(`创建新会话`,`Create a new session`)}]}function ZD({commands:e,active:t,onHover:n,onPick:i,grouped:a=!0}){let o=(0,P.useRef)(null),s=JD(o,400,e.length);return(0,P.useLayoutEffect)(()=>{o.current?.querySelector(`[aria-selected="true"]`)?.scrollIntoView({block:`nearest`})},[t,e.length]),(0,F.jsx)(kp,{ref:o,className:YD.menu,"data-trigger-menu":``,style:{maxHeight:s},children:(0,F.jsxs)(`div`,{className:YD.viewport,role:`listbox`,"aria-label":r(`指令`,`Commands`),"aria-activedescendant":e[t]?`pi-command-${t}`:void 0,children:[e.map((o,s)=>(0,F.jsxs)(P.Fragment,{children:[a&&(s===0||o.section!==e[s-1]?.section)&&(0,F.jsx)(`div`,{className:YD.sectionTitle,role:`presentation`,children:o.section===`add`?r(`添加`,`Add`):r(`指令`,`Commands`)}),(0,F.jsxs)(`button`,{id:`pi-command-${s}`,type:`button`,role:`option`,"aria-selected":s===t,className:`${YD.item} ${s===t?YD.active:``}`,onMouseDown:e=>{e.preventDefault(),i(o)},onMouseMove:s===t?void 0:()=>n(s),children:[o.icon&&(0,F.jsx)(`span`,{className:YD.itemIcon,"aria-hidden":!0,children:(0,F.jsx)(o.icon,{size:14})}),(0,F.jsx)(`span`,{className:YD.itemName,children:o.label??o.name}),o.label&&o.label.toLowerCase()!==o.name.toLowerCase()&&(0,F.jsx)(`span`,{className:YD.itemAlias,children:o.name}),o.description&&(0,F.jsx)(`span`,{className:YD.itemDescription,children:o.description})]})]},`${o.pluginId??`pi`}:${o.name}`)),e.length===0&&(0,F.jsx)(`div`,{className:YD.groupTitle,children:r(`没有匹配的指令`,`No matching commands`)})]})})}var QD={mask:`_mask_dzmab_3`,"fade-in":`_fade-in_dzmab_1`,wrap:`_wrap_dzmab_27`,illustration:`_illustration_dzmab_37`,title:`_title_dzmab_42`,desc:`_desc_dzmab_47`};function $D({disabled:e,labels:t}){return(0,jt.createPortal)((0,F.jsx)(`div`,{className:QD.mask,role:`status`,children:(0,F.jsxs)(`div`,{className:QD.wrap,children:[(0,F.jsx)(`div`,{className:QD.illustration,"aria-hidden":`true`,children:e?(0,F.jsx)(tO,{}):(0,F.jsx)(eO,{})}),(0,F.jsx)(`div`,{className:QD.title,children:t.title}),!e&&t.desc!==void 0&&(0,F.jsx)(`div`,{className:QD.desc,children:t.desc})]})}),document.body)}var eO=()=>(0,F.jsxs)(`svg`,{width:`115`,height:`84`,viewBox:`0 0 115 84`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,F.jsxs)(`g`,{clipPath:`url(#piwDropOverlayClip)`,children:[(0,F.jsx)(`rect`,{y:`17.0742`,width:`44.1832`,height:`43.6431`,rx:`12`,transform:`rotate(-22.7338 0 17.0742)`,fill:`#9CE5ED`}),(0,F.jsx)(`rect`,{x:`73.4043`,y:`8.54297`,width:`43.7267`,height:`50.5284`,rx:`8`,transform:`rotate(17.403 73.4043 8.54297)`,fill:`#679EFE`}),(0,F.jsx)(`path`,{d:`M30.4917 28.1369L40.8865 33.4564L37.2232 34.9524L29.5302 31.0159L26.7919 39.2122L23.1285 40.7082L26.8287 29.6338L16.8967 24.5516L20.5601 23.0556L27.7902 26.7549L30.3639 19.052L34.0273 17.556L30.4917 28.1369Z`,fill:`white`}),(0,F.jsx)(`path`,{d:`M77.5088 26.3047L101.057 33.7966`,stroke:`white`,strokeWidth:`3`}),(0,F.jsx)(`path`,{d:`M72.2646 42.7871L86.3938 47.2823`,stroke:`white`,strokeWidth:`3`}),(0,F.jsx)(`path`,{d:`M74.8867 34.5469L98.4353 42.0388`,stroke:`white`,strokeWidth:`3`}),(0,F.jsx)(`rect`,{x:`31.583`,y:`38.6641`,width:`44.9157`,height:`44.3666`,rx:`12`,transform:`rotate(-0.134233 31.583 38.6641)`,fill:`#3964FE`}),(0,F.jsx)(`path`,{d:`M38.9521 73.0337C39.6129 71.7086 41.7113 66.0937 43.5113 61.1663C44.1607 59.3885 46.7484 59.3923 47.4591 61.1465C48.9728 64.8828 50.7969 68.6922 51.9988 69.1925C54.2946 70.1482 57.9854 59.3573 68.0064 70.1801`,stroke:`white`,strokeWidth:`3`}),(0,F.jsx)(`circle`,{cx:`60.6157`,cy:`52.247`,r:`4.38794`,transform:`rotate(22.5996 60.6157 52.247)`,fill:`white`})]}),(0,F.jsx)(`defs`,{children:(0,F.jsx)(`clipPath`,{id:`piwDropOverlayClip`,children:(0,F.jsx)(`rect`,{width:`115`,height:`84`,fill:`white`})})})]}),tO=()=>(0,F.jsxs)(`svg`,{width:`115`,height:`84`,viewBox:`0 0 115 84`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,F.jsx)(`path`,{d:`M29.6829 4.63701L11.0677 12.4368C4.95519 14.998 2.07624 22.0294 4.6374 28.1419L12.2285 46.259C14.7896 52.3715 21.8211 55.2505 27.9336 52.6893L46.5488 44.8895C52.6613 42.3283 55.5403 35.2969 52.9791 29.1844L45.388 11.0673C42.8269 4.9548 35.7954 2.07585 29.6829 4.63701Z`,fill:`#979DA6`}),(0,F.jsx)(`path`,{d:`M30.4915 28.1375L40.8863 33.4569L37.223 34.9529L29.53 31.0165L26.7917 39.2128L23.1283 40.7088L26.8285 29.6344L16.8965 24.5522L20.5599 23.0562L27.79 26.7555L30.3637 19.0526L34.0271 17.5566L30.4915 28.1375Z`,fill:`white`}),(0,F.jsx)(`path`,{d:`M107.496 19.2285L81.0381 10.9357C76.8221 9.61423 72.333 11.9607 71.0116 16.1768L60.6844 49.1246C59.363 53.3406 61.7095 57.8297 65.9255 59.1511L92.383 67.4439C96.599 68.7654 101.088 66.4189 102.41 62.2029L112.737 29.255C114.058 25.039 111.712 20.55 107.496 19.2285Z`,fill:`#979DA6`}),(0,F.jsx)(`path`,{d:`M77.5088 26.3047L101.057 33.7967`,stroke:`white`,strokeWidth:`3`}),(0,F.jsx)(`path`,{d:`M72.2646 42.7871L86.3938 47.2823`,stroke:`white`,strokeWidth:`3`}),(0,F.jsx)(`path`,{d:`M74.8867 34.5469L98.4353 42.0388`,stroke:`white`,strokeWidth:`3`}),(0,F.jsx)(`path`,{d:`M66.5798 30.1418L41.481 30.2006C33.5281 30.2193 27.0962 36.6815 27.1148 44.6343L27.172 69.0742C27.1907 77.0271 33.6529 83.459 41.6057 83.4404L66.7045 83.3816C74.6574 83.363 81.0894 76.9008 81.0707 68.9479L81.0135 44.5081C80.9949 36.5552 74.5327 30.1232 66.5798 30.1418Z`,fill:`#F59E0B`}),(0,F.jsx)(`path`,{d:`M54 70.7969C61.732 70.7969 68 64.5289 68 56.7969C68 49.0649 61.732 42.7969 54 42.7969C46.268 42.7969 40 49.0649 40 56.7969C40 64.5289 46.268 70.7969 54 70.7969Z`,stroke:`white`,strokeWidth:`3.5`}),(0,F.jsx)(`path`,{d:`M44 46.7969L64 66.7969`,stroke:`white`,strokeWidth:`3.5`,strokeLinecap:`round`})]});function nO(e){let t=[],n=e;for(;;){let e=/(^|\n\n)附件 ("(?:\\.|[^"\\])*"):([^\n]+)$/u.exec(n);if(!e||!/[\\/]pi-web[\\/]attachments[\\/][a-f0-9]{64}[\\/]/u.test(e[3]))break;let r;try{r=JSON.parse(e[2])}catch{break}t.unshift({name:r,image:/\.(?:png|jpe?g|webp|gif)$/iu.test(r)}),n=n.slice(0,e.index)}return{text:n,attachments:t}}var rO={keys:`_keys_38b9q_1`,key:`_key_38b9q_1`,tooltip:`_tooltip_38b9q_20`,separator:`_separator_38b9q_30`,joined:`_joined_38b9q_32`};function iO({keys:e,variant:t=`plain`,className:r}){return(0,F.jsx)(`span`,{className:n(rO.keys,t===`tooltip`&&rO.tooltip,t===`tooltip`&&e.includes(`+`)&&rO.joined,r),children:e.map((e,t)=>(0,F.jsx)(`kbd`,{className:e===`+`?rO.separator:rO.key,children:e},t))})}var aO={bubble:`_bubble_ugtpz_1`,"tooltip-in":`_tooltip-in_ugtpz_1`,label:`_label_ugtpz_26`},oO={pointer:`pointer`,keyboard:`keyboard`},sO=`data-input-modality`,cO=new Set([`Tab`,`Home`,`End`,`PageUp`,`PageDown`]),lO=!1,uO=!1,dO;function fO(){document.documentElement.setAttribute(sO,uO?oO.pointer:oO.keyboard)}function pO(){return lO}typeof window<`u`&&(window.addEventListener(`pointerdown`,()=>{lO=!0,uO=!0,dO=void 0,fO()},!0),window.addEventListener(`keydown`,e=>{typeof e.key==`string`&&(lO=!1,e.isComposing?dO=void 0:(dO=e.composedPath()[0],(cO.has(e.key)||e.key.startsWith(`Arrow`))&&(uO=!1,fO())))},!0),window.addEventListener(`focusin`,e=>{dO!==void 0&&e.composedPath()[0]!==dO&&(dO=void 0,uO&&(uO=!1,fO()))},!0),window.addEventListener(`blur`,()=>{dO=void 0}));var mO=(0,P.createContext)(null);function hO({label:e,shortcutKeys:t,side:n=`right`,align:r=`center`,delayMs:i=0,gap:a=8,disabled:o=!1,portal:s=!1,maxWidth:c,children:l}){let u=(0,P.useRef)(null),d=l.props.ref,f=(0,P.useCallback)(e=>{u.current=e,typeof d==`function`?d(e):d!=null&&(d.current=e)},[d]),[p,m]=(0,P.useState)(null),h=(0,P.useRef)(null),g=p===null?null:typeof e==`function`?e():e,_=p===null?0:n===`right`?p.top+(p.bottom-p.top)/2:n===`top`?p.top-a:p.bottom+a,v=(0,P.useRef)(null),y=(0,P.useRef)({hover:!1,focus:!1}),b=(0,P.useContext)(mO),[x,S]=(0,P.useState)(!1),C=(0,P.useCallback)(e=>{b?.(e)},[b]),w=p!==null&&!o;(0,P.useEffect)(()=>{let e=h.current;if(p===null||!w||x||e===null)return;let t,i=n,o=()=>{if(t===void 0)return;let{inlineSize:o,blockSize:s}=t,c=n===`right`?0:r===`end`?o:o/2,l=Math.max(12,Math.min(p.x-c,window.innerWidth-12-o)),u=p.bottom+a+s<=window.innerHeight-12,d=p.top-a-s>=12;i===`bottom`&&!u&&d?i=`top`:i===`top`&&!d&&u&&(i=`bottom`),e.style.left=`${l+c}px`,e.style.top=`${i===`right`?(p.top+p.bottom)/2:i===`top`?p.top-a:p.bottom+a}px`,e.dataset.side=i,e.style.visibility=`visible`},s=new ResizeObserver(e=>{t=e[0]?.borderBoxSize[0],o()});return s.observe(e,{box:`border-box`}),window.addEventListener(`resize`,o),()=>{s.disconnect(),window.removeEventListener(`resize`,o)}},[r,a,p,n,x,w]),(0,P.useEffect)(()=>(C(w),()=>{C(!1)}),[C,w]);let T=(0,P.useCallback)(()=>{v.current!==null&&(clearTimeout(v.current),v.current=null)},[]);(0,P.useEffect)(()=>(o&&(T(),y.current={hover:!1,focus:!1},m(null)),T),[T,o]);let E=()=>{if(o)return;let e=u.current;if(e===null)return;let t=e.getBoundingClientRect();m({x:n===`right`?t.right+10:r===`end`?t.right:t.left+t.width/2,top:t.top,bottom:t.bottom}),C(!0)},D=()=>{T(),i<=0?E():v.current=setTimeout(()=>{v.current=null,E()},i)},O=()=>{m(null),C(!1)},k=()=>{T(),!y.current.hover&&!y.current.focus&&O()},ee=w&&!x&&(0,F.jsxs)(`span`,{ref:h,className:aO.bubble,"data-side":n,"data-portal":s||void 0,"data-align":r,"data-has-shortcut":t?.length?!0:void 0,style:{left:p.x,top:_,visibility:`hidden`,...c===void 0?{}:{maxWidth:c}},role:`tooltip`,"aria-label":t?.length?[g,t.join(` `)].filter(Boolean).join(` `):void 0,children:[g&&(0,F.jsx)(`span`,{className:aO.label,children:g}),t!==void 0&&t.length>0&&(0,F.jsx)(iO,{keys:t,variant:`tooltip`})]});return(0,F.jsxs)(mO.Provider,{value:S,children:[(0,P.cloneElement)(l,{ref:f,onMouseEnter:e=>{l.props.onMouseEnter?.(e),y.current.hover=!0,D()},onMouseLeave:e=>{l.props.onMouseLeave?.(e),y.current.hover=!1,T(),O()},onClick:e=>{l.props.onClick?.(e),y.current.focus=!1,T(),O()},onFocus:e=>{l.props.onFocus?.(e),pO()||(y.current.focus=!0,T(),E())},onBlur:e=>{l.props.onBlur?.(e),y.current.focus=!1,k()}}),s?ee!==!1&&(0,jt.createPortal)(ee,document.body):ee]})}var gO={dock:`_dock_1dh5u_3`,panel:`_panel_1dh5u_11`,header:`_header_1dh5u_40`,lead:`_lead_1dh5u_57`,chevron:`_chevron_1dh5u_57`,count:`_count_1dh5u_58`,list:`_list_1dh5u_59`,row:`_row_1dh5u_60`,content:`_content_1dh5u_61`,actions:`_actions_1dh5u_62`,action:`_action_1dh5u_62`,editor:`_editor_1dh5u_67`,status:`_status_1dh5u_69`,error:`_error_1dh5u_70`,kind:`_kind_1dh5u_79`,preview:`_preview_1dh5u_80`,attachments:`_attachments_1dh5u_81`,file:`_file_1dh5u_83`,paused:`_paused_1dh5u_86`};function _O({session:e,connected:t,onUpdate:n}){let[i,a]=(0,P.useState)(!0),[o,s]=(0,P.useState)(null),[c,l]=(0,P.useState)(null),[u,d]=(0,P.useState)(``),f=(0,P.useRef)(!1),p=(0,P.useId)(),m=(0,P.useRef)(null),h=(0,P.useRef)(null);(0,P.useLayoutEffect)(()=>{if(h.current&&o===null&&c===null){let e=document.activeElement;(!e||e===document.body||m.current?.contains(e))&&m.current?.querySelector(`[data-prompt-id="${CSS.escape(h.current)}"] [data-edit-prompt]`)?.focus(),h.current=null}},[o,c,e?.queuedPrompts]);let g=[...(e?.promptQueue?.steering??[]).map((e,t)=>({id:`steer-${t}`,label:r(`引导`,`Steer`),...nO(e)})),...(e?.promptQueue?.followUp??[]).map((e,t)=>({id:`native-${t}`,label:r(`排队`,`Queue`),...nO(e)})),...(e?.queuedPrompts??[]).map(e=>({id:e.id,label:r(`排队`,`Queue`),text:e.text,attachments:e.attachments,item:e}))];if((0,P.useEffect)(()=>{g.length===0&&a(!0),o&&!g.some(e=>e.id===o.id&&e.item?.status===`queued`)&&s(null)},[g.length,o,e?.queuedPrompts]),!g.length&&!e?.hasPendingPrompts)return null;let y=g.length===1||!i||o!==null||c!==null,b=r(`${g.length} 条待处理提示词`,`${g.length} pending prompts`),x=e=>{h.current=e},S=async(e,i)=>{if(f.current||!t)return!1;f.current=!0,l(e.id),d(``);try{return await n(e.id,e.revision,i),!0}catch(e){return d(e instanceof Error?e.message:r(`队列操作失败`,`Queue action failed`)),!1}finally{f.current=!1,l(null)}},C=async()=>{if(!o)return;let e=o;await S(e,{kind:`edit`,text:e.text})&&(s(null),x(e.id))},T=(e,t,n,r,i=!1)=>(0,F.jsx)(hO,{portal:!0,label:e,side:`top`,delayMs:500,disabled:t,children:(0,F.jsx)(`button`,{className:gO.action,type:`button`,"aria-label":e,disabled:t,onClick:n,"data-edit-prompt":i||void 0,children:r})});return(0,F.jsx)(`section`,{className:gO.dock,"aria-label":r(`待处理提示词`,`Pending prompts`),"data-queue-dock":``,children:(0,F.jsxs)(`div`,{className:gO.panel,children:[g.length>1&&(0,F.jsxs)(`button`,{type:`button`,className:gO.header,"aria-label":b,"aria-controls":p,"aria-expanded":y,disabled:o!==null||c!==null,onClick:()=>a(e=>!e),children:[(0,F.jsx)(`span`,{className:gO.lead,"aria-hidden":!0,children:(0,F.jsx)(D,{})}),(0,F.jsx)(`span`,{className:gO.count,role:`status`,children:b}),!y&&g.some(e=>e.item?.status===`sending`)&&(0,F.jsx)(`span`,{className:gO.status,children:r(`发送中…`,`Sending…`)}),(0,F.jsx)(`span`,{className:gO.chevron,"aria-hidden":!0,children:y?(0,F.jsx)(E,{}):(0,F.jsx)(M,{})})]}),g.length===0&&(0,F.jsxs)(`div`,{className:gO.header,children:[(0,F.jsx)(`span`,{className:gO.lead,"aria-hidden":!0,children:(0,F.jsx)(D,{})}),(0,F.jsx)(`span`,{className:gO.count,role:`status`,children:r(`等待 Pi 接收`,`Waiting for Pi`)})]}),(0,F.jsx)(`ol`,{ref:m,id:p,className:gO.list,hidden:!y,children:g.map(n=>{let i=n.item,a=!t||c!==null||i?.status===`sending`;return(0,F.jsxs)(`li`,{className:gO.row,"data-prompt-id":n.id,children:[g.length===1&&(0,F.jsx)(`span`,{className:gO.lead,"aria-hidden":!0,children:(0,F.jsx)(D,{})}),(0,F.jsx)(`span`,{className:gO.kind,children:n.label}),(0,F.jsxs)(`div`,{className:gO.content,children:[n.attachments.length>0&&(0,F.jsx)(`span`,{className:gO.attachments,children:n.attachments.map((e,t)=>(0,F.jsxs)(`span`,{className:gO.file,title:e.name,children:[(0,F.jsx)(_,{path:e.name}),(0,F.jsx)(`span`,{children:e.name})]},t))}),o?.id===n.id?(0,F.jsx)(`textarea`,{className:gO.editor,autoFocus:!0,rows:2,maxLength:32e3,"aria-label":r(`编辑排队提示词`,`Edit queued prompt`),value:o.text,disabled:c!==null,onChange:e=>s({...o,text:e.target.value}),onKeyDown:e=>{e.nativeEvent.isComposing||e.keyCode===229||(e.key===`Escape`&&(e.preventDefault(),s(null),x(n.id)),e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),C()))}}):n.text&&(0,F.jsx)(`span`,{className:gO.preview,title:n.text,children:n.text}),i?.error&&(0,F.jsx)(`span`,{className:gO.error,role:`alert`,children:i.error})]}),i?.status===`sending`&&(0,F.jsx)(`span`,{className:gO.status,role:`status`,children:r(`发送中…`,`Sending…`)}),i&&(0,F.jsx)(`div`,{className:gO.actions,children:o?.id===n.id?(0,F.jsxs)(F.Fragment,{children:[T(r(`保存修改`,`Save changes`),a||!o.text.trim()&&n.attachments.length===0,()=>{C()},(0,F.jsx)(A,{})),T(r(`取消编辑`,`Cancel edit`),c!==null,()=>{s(null),x(n.id)},(0,F.jsx)(O,{}))]}):(0,F.jsxs)(F.Fragment,{children:[T(r(`编辑`,`Edit`),a,()=>{s({id:i.id,revision:i.revision,text:i.text}),d(``)},(0,F.jsx)(ee,{}),!0),T(r(`删除`,`Delete`),a,()=>{S(i,{kind:`remove`})},(0,F.jsx)(w,{})),T(r(`发送(引导)`,`Send (steer)`),a||!!e?.idle||!!e?.interactions?.length,()=>{S(i,{kind:`steer`})},(0,F.jsx)(v,{}))]})})]},n.id)})}),u&&(0,F.jsx)(`div`,{className:gO.error,role:`alert`,children:u}),e?.paused&&(0,F.jsx)(`div`,{className:gO.paused,role:`status`,children:r(`已暂停,继续后处理`,`Paused; processed on resume`)})]})})}var vO={controls:`_controls_1d60f_1`,action:`_action_1d60f_2`};function yO({hasDraft:e,canSend:t,canStop:n,pauseLabel:i,pauseTitle:a,pauseIcon:o,onStop:s}){let c=e=>e.preventDefault(),l=(0,F.jsx)(hO,{label:a??i,side:`top`,delayMs:500,disabled:!n,children:(0,F.jsx)(`button`,{className:e?vO.action:en.primary,type:`button`,"aria-label":i,disabled:!n,onMouseDown:c,onClick:s,children:o??(0,F.jsx)(pe,{size:16})})});return(0,F.jsxs)(`div`,{className:vO.controls,role:`group`,"aria-label":r(`追加提示词`,`Append prompt`),children:[l,e&&(0,F.jsx)(hO,{label:r(`当前任务完成后排队处理`,`Queue after the current task finishes`),shortcutKeys:[`Enter`],side:`top`,delayMs:500,disabled:!t,children:(0,F.jsx)(`button`,{className:en.primary,type:`submit`,"aria-label":r(`发送消息`,`Send message`),disabled:!t,onMouseDown:c,children:(0,F.jsx)(C,{size:16})})})]})}function bO(e,t,n){let r=(0,P.useRef)(null),i=(0,P.useRef)(null),a=(0,P.useRef)(null),o=(0,P.useRef)(!0),s=(0,P.useRef)(0),[c,l]=(0,P.useState)(!1),u=(0,P.useCallback)(()=>{let e=r.current;e&&(e.scrollTop=e.scrollHeight,s.current=e.scrollTop,l(!1))},[]),d=(0,P.useCallback)(()=>{o.current=!0,u()},[u]),f=(0,P.useCallback)(()=>{let e=r.current;if(!e)return;let t=e.scrollHeight-e.clientHeight-e.scrollTop;e.scrollTop<s.current-1?o.current=!1:t<=24&&(o.current=!0),s.current=e.scrollTop,l(!o.current&&t>1)},[]),p=(0,P.useCallback)(e=>{e.deltaY<0&&(o.current=!1)},[]);return(0,P.useLayoutEffect)(()=>{if(o.current=!0,l(!1),!t)return;u();let e=new ResizeObserver(()=>{let e=r.current;e&&(e.style.setProperty(`--piw-composer-height`,`${a.current?.getBoundingClientRect().height??152}px`),o.current?u():l(e.scrollHeight-e.clientHeight-e.scrollTop>1))});for(let t of[r.current,i.current,a.current])t&&e.observe(t);return()=>e.disconnect()},[e,t,u]),(0,P.useLayoutEffect)(()=>{t&&n&&d()},[t,n,d]),(0,P.useLayoutEffect)(()=>{t&&o.current&&u()}),{scroll:r,content:i,composer:a,onScroll:f,onWheel:p,showLatest:t&&c,returnToLatest:d}}function xO({message:e,results:t,loadImage:n,running:i=!1,onInspect:a,cwd:o}){if(e.role===`tool`&&e.toolCallId&&t.has(e.toolCallId))return null;if(e.role===`user`){let t=e.blocks.filter(e=>e.kind===`text`).map(e=>e.text).join(`
|
|
59
59
|
`),i=e.localFiles?{text:t,attachments:e.localFiles.map(e=>({name:e.name,image:/\.(?:png|jpe?g|webp|gif)$/iu.test(e.name)||/^image\/(?:png|jpeg|webp|gif)$/.test(e.type)}))}:nO(t),a=e.blocks.map((e,t)=>({block:e,index:t})).filter(({block:e})=>e.kind===`image`),o=i.attachments.filter(e=>e.image),s=e.localFiles?.filter(e=>/\.(?:png|jpe?g|webp|gif)$/iu.test(e.name)||/^image\/(?:png|jpeg|webp|gif)$/.test(e.type));return(0,F.jsx)(`div`,{className:nn.userRow,"data-message-role":`user`,children:(0,F.jsxs)(`div`,{className:nn.userStack,children:[(a.length>0||i.attachments.some(e=>!e.image))&&(0,F.jsxs)(`div`,{className:nn.attachmentRow,"data-message-attachments":!0,children:[a.map(({index:t},c)=>(0,F.jsx)(Vp,{name:o[c]?.name??s?.[c]?.name??r(`图片`,`Image`),messageId:e.id,index:t,file:s?.[c],tile:a.length>1||i.attachments.length>a.length,loadImage:n},t)),i.attachments.filter(e=>!e.image).map((e,t)=>(0,F.jsxs)(`span`,{className:nn.fileCard,title:e.name,children:[(0,F.jsx)(_,{path:e.name,className:nn.fileIcon}),(0,F.jsxs)(`span`,{className:nn.fileContent,children:[(0,F.jsx)(`span`,{className:nn.fileName,children:e.name}),(0,F.jsxs)(`span`,{className:nn.fileMeta,children:[re(e.name).toUpperCase(),` `,r(`文件`,`file`)]})]})]},`${e.name}-${t}`))]}),i.text&&(0,F.jsx)(`div`,{className:nn.bubble,children:i.text})]})})}return(0,F.jsx)(`div`,{className:`pi-message`,"data-message-role":e.role,children:e.blocks.map((e,n)=>e.kind===`thinking`?(0,F.jsx)(cf,{text:e.text,running:i},n):e.kind===`toolCall`?(0,F.jsx)(ep,{block:e,result:e.toolCallId?t.get(e.toolCallId):void 0,running:i,cwd:o,onInspect:e.toolCallId&&a?()=>a(e.toolCallId):void 0},e.toolCallId||n):e.kind===`image`?(0,F.jsx)(`div`,{className:`pi-image-note`,children:e.text},n):(0,F.jsx)(rf,{text:e.text},n))})}function SO({turn:e,results:t,model:n,loadImage:i,onInspect:a,renderPluginSlot:o,renderToolView:s,artifactTools:c,viewTools:l,running:u=!1,cwd:d,superseded:f=!1}){let p=[...e.messages].reverse().find(e=>e.role===`assistant`&&e.blocks.some(e=>e.kind===`text`&&e.text.trim())),m=p?.blocks.filter(e=>e.kind===`text`)??[],h=[];for(let t of e.messages)t.role===`assistant`&&t.blocks.forEach((e,n)=>{t===p&&e.kind===`text`||e.kind===`toolCall`&&(l.includes(e.toolName??``)||c.includes(e.toolName??``))||h.push({message:t,block:e,index:n})});let[g,_]=(0,P.useState)(!1),v=h.filter(({block:e})=>e.kind===`toolCall`).length,y=new Set(h.filter(({block:e})=>e.kind!==`toolCall`).map(({message:e})=>e.id)).size,b=m.map(e=>e.text).join(`
|
|
60
60
|
`),x=u||g,[S,C]=(0,P.useState)(new Set),w=e.messages.filter(e=>e.role===`assistant`&&e.error),T=[...e.messages].reverse().find(e=>e.role===`assistant`),E=f||T&&!T.error&&T.id!==w.at(-1)?.id?[]:w.filter(e=>!S.has(e.id));return(0,F.jsxs)(`div`,{className:`pi-turn`,"data-turn":e.index,children:[e.messages.filter(e=>e.role===`user`||e.role===`notice`).map(e=>(0,F.jsx)(xO,{message:e,results:t,loadImage:i},e.id)),h.length>0&&(0,F.jsxs)(F.Fragment,{children:[m.length>0&&(0,F.jsx)(tp,{toolCount:v,messageCount:y,open:x,onToggle:()=>_(e=>!e)}),(x||m.length===0)&&(0,F.jsx)(`div`,{className:`pi-turn-process-content`,children:h.map(({message:e,block:n,index:r})=>(0,F.jsx)(xO,{message:{...e,blocks:[n]},results:t,loadImage:i,running:e.id===`stream`,cwd:d,onInspect:a},`${e.id}-${r}`))})]}),up(e.messages,l).map(({key:e,call:n})=>(0,F.jsx)(`div`,{"data-tool-view":n.toolName,children:s?.(n,n.toolCallId?t.get(n.toolCallId):void 0,u&&!t.has(n.toolCallId??``))},e)),m.length>0&&p&&(0,F.jsx)(xO,{message:{...p,blocks:m},results:t,loadImage:i,running:p.id===`stream`}),e.messages.filter(e=>e.role===`tool`&&(!e.toolCallId||!t.has(e.toolCallId))).map(e=>(0,F.jsx)(xO,{message:e,results:t,loadImage:i},e.id)),E.map(e=>(0,F.jsxs)(`div`,{className:`pi-model-error`,role:`alert`,children:[(0,F.jsxs)(`div`,{className:`pi-model-error-title`,children:[(0,F.jsx)(`strong`,{children:r(`模型请求失败`,`Model request failed`)}),(0,F.jsx)(`button`,{type:`button`,className:`pi-error-dismiss`,"aria-label":r(`关闭错误`,`Dismiss error`),onClick:()=>C(t=>new Set(t).add(e.id)),children:`×`})]}),(0,F.jsx)(`span`,{children:/usage limit has been reached/i.test(e.error??``)?r(`模型服务的使用额度已耗尽。请切换模型或等待额度恢复后重试。`,`The model service usage limit has been reached. Switch models or try again after the limit resets.`):e.error})]},`${e.id}-error`)),!u&&E.length===0&&(p||e.usage&&e.usage.totalTokens>0)&&(0,F.jsx)(ip,{text:b,timestamp:p?.timestamp,usage:e.usage,model:p?.model??n}),o(`turn.tail`,{id:e.id,completed:!u,messageIds:e.messages.map(e=>e.id),toolCallIds:e.messages.flatMap(e=>e.blocks.filter(e=>e.kind===`toolCall`&&e.toolCallId).map(e=>e.toolCallId))})]})}function CO({hero:e,suspended:t=!1,session:n,connection:i,onSend:a,onUpload:o,onDiscardAttachment:s,onStop:c,onResume:u,onCompact:d,onNewSession:f,commands:p,models:m,modelsStatus:h,onConfigureModels:g,onSetModel:_,onSetThinkingLevel:v,onUpdateQueuedPrompt:y,renderPluginSlot:b,plugins:x,onPluginAction:S}){let C=l(),w=n?.sessionId??``,[T,E]=(0,P.useState)({}),D=T[w],O=D?.text??``,k=D?.attachments??[],ee=D?.error??``,te=e=>{E(t=>({...t,[w]:e(t[w]??{text:``,attachments:[],error:``})}))},ne=e=>te(t=>({...t,text:e})),A=e=>te(t=>({...t,attachments:typeof e==`function`?e(t.attachments):e})),re=e=>te(t=>({...t,error:e})),ie=(0,P.useRef)(T);ie.current=T;let[j,ae]=(0,P.useState)(!1),[oe,M]=(0,P.useState)(null),[se,ce]=(0,P.useState)(0),[le,ue]=(0,P.useState)(0),[de,fe]=(0,P.useState)(!1),pe=(0,P.useRef)(0),me=(0,P.useRef)(null),N=(0,P.useRef)(new Map),he=(0,P.useRef)(new Set),_e=(0,P.useRef)(null),ve=(0,P.useRef)(null),ye=(0,P.useRef)(n?.sessionId);ye.current=n?.sessionId;let be=(0,P.useRef)(!1),xe=(0,P.useRef)(t);(0,P.useEffect)(()=>{xe.current&&!t&&ve.current?.focus(),xe.current=t},[t]);let Se=i===`connected`&&n!==null,Ce=Se&&h===`ready`&&m.length===0,we=Se&&m.some(e=>`${e.provider}/${e.id}`===n.model),Te=Se&&!n.idle,Ee=Se&&!j&&!t,De=Ee&&!Te,Oe=k.length===0&&[`/compact`,`/new`,`/model`].includes(O.trim()),ke=(0,P.useMemo)(()=>VD(XD(),p,x,C),[p,x,C]),Ae=UD(O,ke),je=Ae?.command.pluginId?Ae.command:void 0,Me=Ae?.command.input?`${Ae.token}${/\s$/.test(O)||Ae.text?` `:``}`:null,Ne=Ae?.command.input&&!Ae.text?BD(Ae.command.input.hint,C)??null:null,Pe=Ee&&!n?.interactions?.length&&!(Te&&O.trimStart().startsWith(`/`))&&(h===`ready`&&we||!Te&&(Oe||!!je))&&(O.trim().length>0||k.length>0)&&k.every(e=>e.status===`ready`)&&(!je||k.length===0||je.input?.attachments===!0),Fe=GD(x,n,C,O,k.length),Ie=Fe?.icon,Le=De&&(Fe?.kind===`resume`||Fe?.kind===`invoke`)&&(Fe.kind===`invoke`&&!Fe.sendResultMessage||h===`ready`&&we),Re=Te&&!j&&!t,ze=oe===`slash`?O.slice(1).toLowerCase():``,Be=oe===null?[]:WD(Te?ke.filter(e=>!e.pluginId&&e.name===`file`):ke,ze,oe===`slash`);(0,P.useEffect)(()=>{M(null)},[n?.sessionId,Te]),(0,P.useEffect)(()=>()=>{for(let e of Object.values(ie.current))for(let t of e.attachments)he.current.add(t.key),t.receipt&&t.discard(t.receipt.id).catch(()=>{});for(let e of N.current.values())e.abort();N.current.clear()},[]),(0,P.useEffect)(()=>{if(oe===null)return;let e=e=>{e.target instanceof Node&&!_e.current?.contains(e.target)&&M(null)};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[oe]);let Ve=async e=>{if(Ee&&(De||!e.pluginId&&e.name===`file`)){if(oe===`slash`&&[`file`,`model`,`compact`,`new`].includes(e.name)&&ne(``),M(null),!e.pluginId&&e.name===`file`)me.current?.click();else if(e.pluginId&&e.action&&e.menuOnly){ae(!0);try{await S(e.pluginId,e.action,{args:[]}),re(``)}catch(e){re(e instanceof Error?e.message:String(e))}finally{ae(!1)}}else if(!e.pluginId&&e.name===`model`)ue(e=>e+1);else if(!e.pluginId&&(e.name===`compact`||e.name===`new`)){ae(!0);try{await(e.name===`compact`?d():f())}catch{}finally{ae(!1)}}else ne(`/${BD(e.input?.token,C)??e.name} `),ve.current?.focus()}},He=(0,P.useCallback)((e,t)=>{let n=new AbortController;N.current.set(e,n),o(t,n.signal).then(t=>{he.current.has(e)?s(t.id).catch(()=>{}):A(n=>n.map(n=>n.key===e?{...n,status:`ready`,receipt:t,error:void 0}:n))}).catch(t=>{if(he.current.has(e))return;let n=t instanceof Error?t.message:r(`上传失败`,`Upload failed`);re(n),A(t=>t.map(t=>t.key===e?{...t,status:`error`,error:n}:t))}).finally(()=>{N.current.get(e)===n&&N.current.delete(e)})},[o,s,w]),Ue=(0,P.useRef)(w);(0,P.useEffect)(()=>{let e=Ue.current;if(e===w)return;Ue.current=w;let t=ie.current[e];for(let e of t?.attachments??[])he.current.add(e.key),N.current.get(e.key)?.abort();let n=ie.current[w],r=(n?.attachments??[]).map(e=>({key:ge(),file:e.file,discard:s,status:`uploading`}));E(i=>({...i,...t?{[e]:{...t,attachments:t.attachments.map(e=>({...e,receipt:void 0,status:`error`}))}}:{},...n?{[w]:{...n,attachments:r,error:``}}:{}})),r.forEach(e=>He(e.key,e.file))},[w]);let We=e=>{he.current.add(e.key),N.current.get(e.key)?.abort(),e.receipt&&e.discard(e.receipt.id).catch(()=>{}),e.status===`error`&&!k.some(t=>t.key!==e.key&&t.status===`error`)&&re(``),A(t=>t.filter(t=>t.key!==e.key))},Ge=(0,P.useCallback)(e=>{if(!Ee||e.length===0)return;let t=Math.max(0,20-k.length),n=e.slice(0,t).filter(e=>e.size>0&&e.size<=20971520);n.length===e.length?re(``):re(r(`最多添加 20 个文件,单个文件不得超过 20 MB 且不能为空`,`Add up to 20 nonempty files, each no larger than 20 MB`));let i=n.map(e=>({key:ge(),file:e,discard:s,status:`uploading`}));A(e=>[...e,...i]),i.forEach(e=>He(e.key,e.file))},[k.length,Ee,He,s]);(0,P.useEffect)(()=>{let e=e=>e.dataTransfer?.types.includes(`Files`)??!1,t=()=>{pe.current=0,fe(!1)},n=t=>{e(t)&&(t.preventDefault(),pe.current++,fe(!0))},r=t=>{e(t)&&(t.preventDefault(),t.dataTransfer&&(t.dataTransfer.dropEffect=Ee?`copy`:`none`))},i=t=>{e(t)&&(pe.current=Math.max(0,pe.current-1),pe.current===0&&fe(!1))},a=n=>{if(!e(n))return;n.preventDefault();let r=[...n.dataTransfer?.files??[]];t(),Ge(r)};return document.addEventListener(`dragenter`,n),document.addEventListener(`dragover`,r),document.addEventListener(`dragleave`,i),document.addEventListener(`drop`,a),window.addEventListener(`dragend`,t),()=>{document.removeEventListener(`dragenter`,n),document.removeEventListener(`dragover`,r),document.removeEventListener(`dragleave`,i),document.removeEventListener(`drop`,a),window.removeEventListener(`dragend`,t)}},[Ee,Ge]);let Ke=async(e=Te?`followUp`:void 0)=>{if(!Pe||be.current)return;be.current=!0,ae(!0);let t=O.trim(),n=k;Oe||(ne(``),A([]));try{if(Oe)t===`/model`?ue(e=>e+1):await(t===`/compact`?d():f()),ne(``);else if(je?.pluginId&&je.action&&Ae){re(``);let e=await S(je.pluginId,je.action,{args:Ae.text.split(/\s+/).filter(Boolean),text:Ae.text,attachments:n.map(e=>e.receipt.id)});typeof e?.message==`string`&&e.message?await a(e.message,n.map(e=>e.receipt.id),n.map(e=>e.file)):n.length&&(A(n),re(r(`指令未发送附件,文件仍保留在输入框`,`The command did not send the files; they remain in the composer`))),ne(``)}else await a(t,n.map(e=>e.receipt.id),n.map(e=>e.file),e)}catch{Oe||(ne(t),A(n))}finally{be.current=!1,ae(!1)}},qe=async()=>{if(Re&&!be.current){be.current=!0,ae(!0);try{await c()}catch{}finally{be.current=!1,ae(!1)}}},Je=async()=>{if(Le&&Fe&&!be.current){be.current=!0,ae(!0),re(``);try{await KD(Fe,S,e=>a(e,[],[]),c,()=>ye.current,u)}catch(e){Fe.kind!==`resume`&&ye.current===Fe.sessionId&&re(e instanceof Error?e.message:String(e))}finally{be.current=!1,ae(!1)}}};return(0,F.jsxs)(`div`,{hidden:t,className:`${en.root} ${e?en.hero:``} ${t?en.suspended:``}`,children:[de&&(0,F.jsx)($D,{disabled:!Ee,labels:{title:Ee?r(`松开以上传文件`,`Drop to upload files`):r(`当前无法上传文件`,`Files cannot be uploaded now`),desc:Ee?r(`最多 20 个文件,每个不超过 20 MB`,`Up to 20 files, 20 MB each`):void 0}}),(0,F.jsx)(_O,{session:n,onUpdate:y,connected:Se},n?.sessionId),(0,F.jsxs)(`form`,{ref:_e,className:en.card,"data-composer-card":!0,onSubmit:e=>{e.preventDefault(),Ke()},children:[oe!==null&&(0,F.jsx)(ZD,{commands:Be,active:se,grouped:!ze,onHover:ce,onPick:e=>{Ve(e)}}),(0,F.jsx)(`input`,{ref:me,className:`pi-file-input`,type:`file`,multiple:!0,tabIndex:-1,"aria-label":r(`选择要上传的文件`,`Choose files to upload`),onChange:e=>{Ge([...e.target.files??[]]),e.target.value=``}}),k.length>0&&(0,F.jsx)(`div`,{className:`pi-attachment-rail`,role:`group`,"aria-label":r(`待发送附件`,`Pending attachments`),children:k.map(e=>(0,F.jsx)(Rp,{file:e.file,status:e.status,error:e.error,onRemove:()=>We(e),onRetry:()=>{re(``),A(t=>t.map(t=>t.key===e.key?{...t,status:`uploading`,error:void 0}:t)),He(e.key,e.file)}},e.key))}),(0,F.jsx)(zD,{ref:ve,value:O,claimToken:Me,hint:Ne,editable:Se&&!j&&!t,placeholder:Ce?r(`先连接模型,再开始对话`,`Connect a model to start chatting`):Se&&h===`ready`&&!we?r(`先选择模型,再开始对话`,`Choose a model to start chatting`):Se?n&&x.map(e=>e.definition.composerPlaceholder?.(n,C)).find(Boolean)||r(`给 Pi 发送消息`,`Message Pi`):r(`打开 Pi 中 /web 给出的完整地址`,`Open the full address provided by /web in Pi`),ariaLabel:r(`给当前 Pi 会话发送消息`,`Send a message to the current Pi session`),menuOpen:oe!==null,activeOption:oe!==null&&Be[se]?`pi-command-${se}`:void 0,onChange:e=>{ne(e),De&&/^\/[^\s]*$/.test(e)?(M(`slash`),ce(0)):oe===`slash`&&M(null)},onPaste:e=>{let t=[...e.clipboardData.files];t.length&&(e.preventDefault(),Ge(t))},onKeyDown:e=>{if(!(e.nativeEvent.isComposing||e.keyCode===229)){if(oe!==null){if(e.key===`Escape`){e.preventDefault(),M(null);return}if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault(),ce(t=>(t+(e.key===`ArrowDown`?1:-1)+Be.length)%Math.max(Be.length,1));return}if((e.key===`Enter`||e.key===`Tab`)&&Be[se]){e.preventDefault(),Ve(Be[se]);return}}e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),Ke(Te&&(e.ctrlKey||e.metaKey)?`steer`:Te?`followUp`:void 0))}}}),(0,F.jsxs)(`div`,{className:en.row,children:[(0,F.jsxs)(`div`,{className:en.tools,children:[(0,F.jsx)(`button`,{className:en.add,type:`button`,"aria-label":r(`添加指令`,`Add command`),title:r(`添加指令`,`Add command`),"aria-haspopup":`listbox`,"aria-expanded":oe!==null,disabled:!Ee,onMouseDown:e=>e.preventDefault(),onClick:()=>{M(oe===null?`button`:null),ce(0),ve.current?.focus()},children:(0,F.jsx)(ot,{size:16})}),b(`composer.controls`)]}),(0,F.jsxs)(`div`,{className:en.trailing,children:[Ce?(0,F.jsx)(`button`,{className:`pi-model-setup-trigger`,type:`button`,onClick:g,children:r(`配置模型`,`Set up a model`)}):(0,F.jsx)(jp,{openSignal:le,current:n?.model??null,models:m,disabled:!Se||!n?.idle,onSelect:_,thinkingLevel:n?.thinkingLevel??null,thinkingLevels:n?.thinkingLevels??[],onSelectThinkingLevel:v}),Te?(0,F.jsx)(yO,{hasDraft:O.trim().length>0||k.length>0,canSend:Pe,canStop:Re,pauseLabel:Fe?.label??r(`暂停执行`,`Pause`),pauseTitle:Fe?.title,pauseIcon:Ie?(0,F.jsx)(Ie,{size:16}):void 0,onStop:()=>{qe()}}):Fe?.kind===`invoke`||Fe?.kind===`resume`?(0,F.jsx)(`button`,{className:en.primary,type:`button`,"aria-label":Fe.label,title:Fe.title,disabled:!Le,onClick:()=>{Je()},children:Ie?(0,F.jsx)(Ie,{size:16}):(0,F.jsx)(`svg`,{viewBox:`0 0 16 16`,width:`16`,height:`16`,"aria-hidden":`true`,children:(0,F.jsx)(`path`,{d:`M5 2.5 13 8l-8 5.5z`,fill:`currentColor`})})}):(0,F.jsx)(`button`,{className:en.primary,type:`submit`,"aria-label":r(`发送消息`,`Send message`),disabled:!Pe,children:(0,F.jsx)(`svg`,{viewBox:`0 0 16 16`,width:`16`,height:`16`,"aria-hidden":`true`,children:(0,F.jsx)(`path`,{d:`M8.3125 0.980183C8.66767 1.0531 8.97902 1.20418 9.2627 1.43233C9.48724 1.61297 9.73029 1.85793 9.97949 2.10714L14.707 6.83468L13.293 8.24874L9 3.95577V15.0417H7V3.95577L2.70703 8.24874L1.29297 6.83468L6.02051 2.10714C6.26971 1.85793 6.51277 1.61297 6.7373 1.43233C6.97662 1.23986 7.28445 1.04402 7.6875 0.980183C7.8973 0.947006 8.1031 0.95516 8.3125 0.980183Z`,fill:`currentColor`})})})]})]}),Te&&O.trimStart().startsWith(`/`)&&(0,F.jsx)(`div`,{className:`pi-prompt-hint`,children:r(`运行中不执行斜杠指令,请等待当前回复结束`,`Wait for the current reply before running slash commands`)})]}),ee&&(0,F.jsx)(`div`,{className:`pi-error`,role:`alert`,children:ee})]})}function wO({rightbarControl:e,composerInteraction:t,session:n,streaming:i,connection:a,error:o,onDismissError:s,onSend:c,onLoadImage:l,onUpload:u,onDiscardAttachment:d,onStop:f,onResume:p,onCompact:m,onNewSession:h,commands:g,models:_,modelsStatus:v,onConfigureModels:y,onSetModel:b,onSetThinkingLevel:x,onUpdateQueuedPrompt:S,renderPluginSlot:C,renderToolView:w,plugins:T,onPluginAction:E}){let[D,O]=(0,P.useState)(`chat`),[k,ee]=(0,P.useState)(null),[te,ne]=(0,P.useState)(null),A=te&&n?.sessionId===te.sessionId&&n.messages.some(e=>e.role===`user`&&!te.knownIds.has(e.id)&&nO(e.blocks.filter(e=>e.kind===`text`).map(e=>e.text).join(`
|
|
61
|
-
`)).text===te.text);(0,P.useEffect)(()=>{te&&(A||n&&n.sessionId!==te.sessionId)&&ne(null)},[te,A,n?.sessionId]);let re=te&&!A&&n?.sessionId===te.sessionId?{id:te.id,role:`user`,timestamp:te.timestamp,blocks:[{kind:`text`,text:te.text},...te.files.filter(e=>/\.(?:png|jpe?g|webp|gif)$/iu.test(e.name)||/^image\/(?:png|jpeg|webp|gif)$/.test(e.type)).map(()=>({kind:`image`,text:``}))],localFiles:te.files}:null,ie=pf(n,i,a,re!==null),j=mf(ff(n,i,a,re!==null),n?.sessionId),ae=T.flatMap(e=>e.definition.workbench?.toolViews?.flatMap(e=>e.tools)??[]),oe=cp(n?.sessionId,[...n?.messages??[],...re?[re]:[],...i?[i]:[]],ae),M=n===null||oe.messages.length===0&&ie===null,se=async(e,t,r,i)=>{if(!n)return;if(i){await c(e,t,i);return}let a=`pending-${ge()}`;ne({id:a,sessionId:n.sessionId,text:e,files:r,knownIds:new Set(n.messages.map(e=>e.id)),timestamp:new Date().toISOString()});try{await c(e,t)}catch(e){throw ne(e=>e?.id===a?null:e),e}},ce=(0,P.useRef)(null),{scroll:le,content:ue,composer:de,onScroll:fe,onWheel:pe,showLatest:me,returnToLatest:N}=bO(n?.sessionId,!M&&D===`chat`,re?.id),[he,_e]=(0,P.useState)(0);(0,P.useLayoutEffect)(()=>{let e=ce.current;if(!e)return;let t=()=>_e(e.getBoundingClientRect().width);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let ve=n?.cwd.split(/[\\/]/).filter(Boolean).at(-1)||r(`Pi 工作区`,`Pi workspace`),ye=oe.messages,be=fp(ye),xe=lp(ye);return(0,F.jsxs)(`div`,{ref:ce,className:$t.root,"data-phase":M?`hero`:`active`,style:{"--piw-conversation-column-width":`${he}px`},children:[M&&(0,F.jsx)(`div`,{className:$t.heroTools,children:e}),n&&!M&&(0,F.jsxs)(`header`,{className:$t.header,children:[(0,F.jsxs)(`div`,{className:$t.titleRow,children:[(0,F.jsx)(`div`,{className:$t.titleCluster,children:(0,F.jsx)(`div`,{className:$t.crumbs,children:(0,F.jsx)(`span`,{className:`${$t.crumb} ${$t.crumbCurrent}`,children:n.name||r(`新会话`,`New chat`)})})}),(0,F.jsxs)(`div`,{className:$t.headerActions,children:[e,(0,F.jsx)($e,{state:a===`connected`?n.idle?`done`:`ongoing`:`error`}),(0,F.jsx)(`span`,{className:`pi-header-state`,children:a===`connected`?n.idle?r(`已连接`,`Connected`):r(`运行中`,`Running`):r(`已断开`,`Disconnected`)})]})]}),(0,F.jsxs)(`div`,{className:$t.tabs,role:`tablist`,"aria-label":r(`会话视图`,`Session views`),children:[(0,F.jsx)(`button`,{className:`${$t.tab} ${D===`chat`?$t.tabActive:``}`,role:`tab`,"aria-selected":D===`chat`,type:`button`,onClick:()=>O(`chat`),children:r(`对话`,`Chat`)}),(0,F.jsx)(`button`,{className:`${$t.tab} ${D===`trajectory`?$t.tabActive:``}`,role:`tab`,"aria-selected":D===`trajectory`,type:`button`,onClick:()=>O(`trajectory`),children:r(`轨迹`,`Trajectory`)})]})]}),(0,F.jsx)(`div`,{className:$t.body,children:(0,F.jsxs)(`div`,{ref:le,className:$t.scrollBody,"data-conversation-scroll":``,onScroll:fe,onWheel:pe,children:[!M&&(0,F.jsx)(`div`,{ref:ue,className:$t.viewArea,children:D===`chat`?(0,F.jsx)(`div`,{className:tn.root,children:(0,F.jsx)(`div`,{className:tn.scroll,children:(0,F.jsx)(`div`,{className:tn.column,children:(0,F.jsxs)(F.Fragment,{children:[xe.map(e=>(0,F.jsx)(SO,{turn:e,results:be,model:n?.model??null,loadImage:l,cwd:n?.cwd,renderPluginSlot:C,renderToolView:w,viewTools:ae,artifactTools:T.flatMap(e=>e.definition.artifactTools??[]),running:e===xe.at(-1)&&!n?.idle||e.messages.some(e=>e.id===`stream`),superseded:e!==xe.at(-1),onInspect:e=>{ee(e),O(`trajectory`)}},dp(e,ae))),ie&&(0,F.jsx)(df,{state:ie,elapsedSeconds:j})]})})})}):(0,F.jsx)(Dp,{messages:ye,inspectCallId:k})}),(0,F.jsx)(`div`,{ref:de,className:$t.composerSeat,"data-composer-seat":``,children:(0,F.jsxs)(`div`,{className:`${$t.composerStack} ${M?$t.composerHero:``}`,children:[M&&(0,F.jsx)(Qt,{t:e=>({"hero.headline":r(`有什么可以帮你?`,`How can I help?`),"hero.preview":`Pi`})[e]??e,renderSlot:(e,t,n)=>n?.fallback??null}),M&&(0,F.jsx)(`div`,{className:$t.heroWorkspaceRow,children:(0,F.jsxs)(`span`,{className:Zt.workspace,children:[(0,F.jsx)(xt,{size:16}),(0,F.jsx)(`span`,{className:Zt.workspaceLabel,children:ve})]})}),t,(0,F.jsx)(CO,{suspended:t!=null,hero:M,session:n,connection:a,onSend:se,onUpdateQueuedPrompt:S,onUpload:u,onDiscardAttachment:d,onStop:f,onResume:p,onCompact:m,onNewSession:h,commands:g,models:_,modelsStatus:v,onConfigureModels:y,onSetModel:b,onSetThinkingLevel:x,renderPluginSlot:C,plugins:T,onPluginAction:E}),oe.error&&(0,F.jsxs)(`div`,{className:`pi-error`,role:`alert`,children:[oe.error,(0,F.jsx)(`button`,{onClick:oe.retry,children:`Retry view cleanup`})]}),o&&(0,F.jsxs)(`div`,{className:`pi-error pi-error-dismissible`,role:`alert`,children:[(0,F.jsx)(`span`,{children:o}),(0,F.jsx)(`button`,{type:`button`,className:`pi-error-dismiss`,"aria-label":r(`关闭错误`,`Dismiss error`),onClick:s,children:`×`})]})]})}),me&&(0,F.jsx)(`div`,{className:tn.toBottomSlot,children:(0,F.jsx)(`button`,{className:tn.toBottom,type:`button`,"aria-label":r(`回到最新`,`Back to latest`),title:r(`回到最新并继续跟随`,`Back to latest and resume following`),onClick:N,children:(0,F.jsx)(`svg`,{viewBox:`0 0 16 16`,width:`16`,height:`16`,"aria-hidden":`true`,children:(0,F.jsx)(`path`,{d:`M8 2v12m-5-5 5 5 5-5`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`})})})})]})})]})}var TO={button:`_button_cfgyt_4`,md:`_md_cfgyt_24`,sm:`_sm_cfgyt_30`,primary:`_primary_cfgyt_38`,ghost:`_ghost_cfgyt_47`,outline:`_outline_cfgyt_56`,toolbar:`_toolbar_cfgyt_65`,icon:`_icon_cfgyt_73`};function EO({variant:e=`ghost`,size:t=`md`,icon:r,className:i,children:a,...o}){return(0,F.jsxs)(`button`,{type:`button`,className:n(TO.button,TO[e],TO[t],i),...o,children:[r!=null&&(0,F.jsx)(`span`,{className:TO.icon,children:r}),a]})}var DO={root:`_root_w1urq_2`,mask:`_mask_w1urq_14`,dialog:`_dialog_w1urq_22`,content:`_content_w1urq_37`,header:`_header_w1urq_45`,title:`_title_w1urq_53`,close:`_close_w1urq_61`,description:`_description_w1urq_80`,body:`_body_w1urq_89`,footer:`_footer_w1urq_97`};function OO({open:e,onClose:t,title:r,closeLabel:i,description:a,children:o,footer:s,className:c,contentClassName:l,headless:u=!1}){let d=(0,P.useRef)(null);return ze(d,e,t),e?(0,jt.createPortal)((0,F.jsx)(Fe.Provider,{value:d,children:(0,F.jsxs)(`div`,{className:DO.root,role:`presentation`,children:[(0,F.jsx)(`div`,{className:DO.mask,"aria-hidden":`true`,onClick:t}),(0,F.jsx)(`div`,{ref:d,tabIndex:-1,className:n(DO.dialog,c),role:`dialog`,"aria-modal":`true`,"aria-label":r,children:u?o:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`div`,{className:n(DO.content,l),children:[(0,F.jsxs)(`div`,{className:DO.header,children:[(0,F.jsx)(`h2`,{className:DO.title,children:r}),(0,F.jsx)(`button`,{type:`button`,className:DO.close,"aria-label":i,onClick:t,children:(0,F.jsx)(ut,{size:14})})]}),a!==void 0&&a!==``&&(0,F.jsx)(`p`,{className:DO.description,children:a}),o!==void 0&&(0,F.jsx)(`div`,{className:DO.body,children:o})]}),s!==void 0&&(0,F.jsx)(`div`,{className:DO.footer,children:s})]})})]})}),document.body):null}var kO={group:`_group_7dgiw_4`,workspaceLine:`_workspaceLine_7dgiw_5`,workspaceButton:`_workspaceButton_7dgiw_7`,workspaceTitle:`_workspaceTitle_7dgiw_8`,folder:`_folder_7dgiw_9`,folderActive:`_folderActive_7dgiw_10`,unavailable:`_unavailable_7dgiw_11`,chevron:`_chevron_7dgiw_12`,chevronOpen:`_chevronOpen_7dgiw_13`,rowActions:`_rowActions_7dgiw_16`,rowAction:`_rowAction_7dgiw_16`,sessionButton:`_sessionButton_7dgiw_23`,sessionLine:`_sessionLine_7dgiw_24`,sessionTime:`_sessionTime_7dgiw_27`,untitled:`_untitled_7dgiw_31`,renameInput:`_renameInput_7dgiw_32`,error:`_error_7dgiw_38`,menu:`_menu_7dgiw_39`,menuItem:`_menuItem_7dgiw_40`,menuItemNeutral:`_menuItemNeutral_7dgiw_42`,menuHint:`_menuHint_7dgiw_44`};function AO({title:e,active:t,disabled:n,open:i,onOpenChange:a,onRemove:o}){return(0,F.jsx)(MO,{label:r(`${e} 的工作区操作`,`Workspace actions for ${e}`),title:r(`工作区操作`,`Workspace actions`),disabled:n,open:i,onOpenChange:a,items:[{label:r(`从列表移除工作区`,`Remove workspace from list`),icon:(0,F.jsx)(ht,{}),destructive:!0,disabled:t,onSelect:o}],hint:t?r(`请先切换到其他工作区再移除`,`Switch to another workspace before removing`):r(`不删除目录、文件或会话历史`,`Keeps directories, files and session history`)})}function jO({title:e,disabled:t,open:n,onOpenChange:i,onRename:a,onDelete:o}){return(0,F.jsx)(MO,{label:r(`${e} 的会话操作`,`Chat actions for ${e}`),title:r(`会话操作`,`Chat actions`),disabled:t,open:n,onOpenChange:i,items:[{label:r(`重命名`,`Rename`),icon:(0,F.jsx)(pt,{}),onSelect:a},{label:r(`删除会话`,`Delete chat`),icon:(0,F.jsx)(ht,{}),destructive:!0,onSelect:o}]})}function MO({label:e,title:t,disabled:n,open:r,onOpenChange:i,items:a,hint:o}){let s=(0,P.useRef)(null),c=(0,P.useRef)(null),[l,u]=(0,P.useState)({top:0,left:0}),d=(0,P.useRef)({onOpenChange:i});d.current={onOpenChange:i};let f=(e=!0)=>{i(!1),e&&s.current?.focus()};return(0,P.useLayoutEffect)(()=>{if(!r)return;let e=s.current.getBoundingClientRect(),t=c.current.getBoundingClientRect().height;u({top:Math.max(12,Math.min(e.bottom+4,window.innerHeight-t-12)),left:Math.max(12,Math.min(e.right-220,window.innerWidth-232))}),(c.current?.querySelector(`button:not(:disabled)`)??c.current)?.focus();let n=e=>{!c.current?.contains(e.target)&&!s.current?.contains(e.target)&&d.current.onOpenChange(!1)},i=()=>{d.current.onOpenChange(!1),s.current?.focus()};return document.addEventListener(`pointerdown`,n,!0),window.addEventListener(`resize`,i),window.addEventListener(`scroll`,i,!0),()=>{document.removeEventListener(`pointerdown`,n,!0),window.removeEventListener(`resize`,i),window.removeEventListener(`scroll`,i,!0)}},[r]),(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`button`,{ref:s,type:`button`,className:kO.rowAction,disabled:n,"aria-label":e,title:t,"aria-haspopup":`menu`,"aria-expanded":r,onClick:()=>r?f():i(!0),onKeyDown:e=>{(e.key===`ArrowDown`||e.key===`ArrowUp`)&&(e.preventDefault(),i(!0))},children:(0,F.jsx)(at,{})}),r&&(0,jt.createPortal)((0,F.jsxs)(kp,{ref:c,role:`menu`,tabIndex:-1,"aria-label":e,className:kO.menu,style:l,onKeyDown:e=>{if(e.key===`Escape`)e.preventDefault(),e.stopPropagation(),f();else if(e.key===`Tab`)f();else if([`ArrowDown`,`ArrowUp`,`Home`,`End`].includes(e.key)){e.preventDefault();let t=[...c.current?.querySelectorAll(`button:not(:disabled)`)??[]],n=t.indexOf(document.activeElement);t[e.key===`Home`?0:e.key===`End`?t.length-1:e.key===`ArrowDown`?(n+1)%t.length:(n-1+t.length)%t.length]?.focus()}},children:[a.map(e=>(0,F.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`${kO.menuItem} ${e.destructive?``:kO.menuItemNeutral}`,disabled:n||e.disabled,onClick:()=>{f(),e.onSelect()},children:[e.icon,e.label]},e.label)),o&&(0,F.jsx)(`p`,{className:kO.menuHint,children:o})]}),document.body)]})}function NO(e,t,n){let r=Date.parse(e);if(!Number.isFinite(r))return``;let i=Math.max(0,Math.floor((t-r)/6e4));if(i<1)return n===`zh`?`刚刚`:`now`;let[a,o,s]=[[525600,`年`,`yr`],[43200,`个月`,`mo`],[10080,`周`,`wk`],[1440,`天`,`d`],[60,`小时`,`h`],[1,`分钟`,`min`]].find(([e])=>i>=e);return`${Math.floor(i/a)}${n===`zh`?o:s}`}var PO={dialog:`_dialog_s0tgk_1`,editorScope:`_editorScope_s0tgk_21`,header:`_header_s0tgk_26`,title:`_title_s0tgk_35`,crumbBar:`_crumbBar_s0tgk_51`,crumbEditZone:`_crumbEditZone_s0tgk_65`,pathInput:`_pathInput_s0tgk_67`,millerRow:`_millerRow_s0tgk_78`,crumbTrail:`_crumbTrail_s0tgk_91`,crumbSeat:`_crumbSeat_s0tgk_101`,crumb:`_crumb_s0tgk_51`,crumbChevron:`_crumbChevron_s0tgk_128`,crumbEditGlyph:`_crumbEditGlyph_s0tgk_151`,content:`_content_s0tgk_187`,column:`_column_s0tgk_186`,divider:`_divider_s0tgk_216`,rowSeat:`_rowSeat_s0tgk_222`,row:`_row_s0tgk_222`,rowSelected:`_rowSelected_s0tgk_247`,rowIcon:`_rowIcon_s0tgk_252`,rowIconSelected:`_rowIconSelected_s0tgk_257`,rowName:`_rowName_s0tgk_262`,rowChevron:`_rowChevron_s0tgk_274`,status:`_status_s0tgk_279`,error:`_error_s0tgk_280`,loadingFloat:`_loadingFloat_s0tgk_192`,footerBar:`_footerBar_s0tgk_317`,showHiddenToggle:`_showHiddenToggle_s0tgk_333`,showHiddenToggleActive:`_showHiddenToggleActive_s0tgk_357`,footerGap:`_footerGap_s0tgk_361`,footerAction:`_footerAction_s0tgk_365`,createDialog:`_createDialog_s0tgk_370`,createBody:`_createBody_s0tgk_376`,createTitle:`_createTitle_s0tgk_383`,createIn:`_createIn_s0tgk_391`,createInput:`_createInput_s0tgk_398`,createActions:`_createActions_s0tgk_416`};function FO(e){if(typeof e==`object`&&e&&`rpcError`in e){let t=e.rpcError;if(typeof t==`object`&&t&&`message`in t&&typeof t.message==`string`)return t.message}return e instanceof Error?e.message:String(e)}var IO=300,LO=200,RO=250;function zO(e,t){let n=e.crumbs.findIndex(t=>t.path===e.home);if(n===-1)return e.crumbs;let r=e.crumbs.slice(n+1);return[{name:t,path:e.home,hidden:!1},...r]}function BO(e){return e.home.includes(`\\`)?`\\`:`/`}function VO(e){let t=BO(e);return e.path.endsWith(t)?e.path:`${e.path}${t}`}function HO(e,t){let n=BO(e)===`\\`?Math.max(t.lastIndexOf(`\\`),t.lastIndexOf(`/`)):t.lastIndexOf(`/`);return n===-1?null:t.slice(0,n+1)}function UO(e,t,n){let r=HO(e,t);return r===null?{directory:null,tail:null}:{directory:r,tail:r===VO(e)||n!==null&&n.directory===r&&n.landed===e.path?t.slice(r.length):null}}function WO(e,t,n,r){let i=r===null?``:r.toLowerCase(),a=e=>n||!e.hidden||i.startsWith(`.`),o=e=>a(e)&&e.name.toLowerCase().startsWith(i),s=i!==``&&e.some(o);return e.filter(e=>e.path===t?!0:s?o(e):n||!e.hidden)}function GO({entries:e,selectedPath:t,busy:r,onPick:i,showHidden:a,filterPrefix:o,pathEditing:s}){let c=WO(e,t,a,o);return(0,F.jsx)(`div`,{className:PO.column,role:`list`,children:c.map(e=>{let a=e.path===t;return(0,F.jsx)(`span`,{role:`listitem`,className:PO.rowSeat,children:(0,F.jsxs)(`button`,{type:`button`,"aria-current":a||void 0,className:n(PO.row,a&&PO.rowSelected),disabled:r,onMouseDown:s?e=>{e.preventDefault()}:void 0,onClick:()=>{i(e)},children:[a?(0,F.jsx)(xt,{size:16,className:PO.rowIconSelected}):(0,F.jsx)(St,{size:16,className:PO.rowIcon}),(0,F.jsx)(`span`,{className:PO.rowName,children:e.name}),(0,F.jsx)(lt,{size:12,className:PO.rowChevron})]})},e.path)})})}function KO({open:e,listDirectory:t,createDirectory:r,onOpen:i,onClose:a,busy:o,t:s}){let[c,l]=(0,P.useState)(null),[u,d]=(0,P.useState)(null),[f,p]=(0,P.useState)(null),[m,h]=(0,P.useState)(!1),[g,_]=(0,P.useState)(!1),[v,y]=(0,P.useState)(0),[b,x]=(0,P.useState)(null),[S,C]=(0,P.useState)(null),[w,T]=(0,P.useState)(!1),[E,D]=(0,P.useState)(null),[O,k]=(0,P.useState)(!1),[ee,te]=(0,P.useState)(null),ne=(0,P.useRef)(0),A=(0,P.useRef)(null),re=(0,P.useRef)(0),ie=(0,P.useRef)(null),j=(0,P.useRef)(!1);(0,P.useEffect)(()=>()=>{ne.current+=1,re.current+=1,A.current?.abort()},[]);let ae={onCompositionStart:()=>{j.current=!0},onCompositionEnd:()=>{j.current=!1}},oe=(0,P.useCallback)(()=>(A.current?.abort(),A.current=null,++ne.current),[]),M=(0,P.useCallback)(()=>{_(!1),y(e=>e+1)},[]),se=(0,P.useCallback)(e=>{let n=oe(),r=new AbortController;return A.current=r,M(),{seq:n,scan:t(e,r.signal)}},[oe,M,t]),ce=(0,P.useCallback)(e=>{let n=new AbortController;return A.current=n,M(),t(e,n.signal)},[M,t]),le=(0,P.useRef)(!1),ue=(0,P.useRef)({parent:null,child:null});(0,P.useEffect)(()=>{ue.current={parent:c,child:f}},[c,f]);let de=(0,P.useRef)(null),fe=(0,P.useRef)(!1),pe=(0,P.useCallback)((e,t)=>{let{seq:n,scan:r}=se(e);h(!0),t.announce&&x(null);let i=()=>{h(!1),t.closeEditor?C(null):(x(null),fe.current=!0)};r.then(r=>{if(n!==ne.current)return;!t.closeEditor&&e!==void 0&&(de.current={directory:e,landed:r.path});let a=!1,o=()=>{a||n!==ne.current||(a=!0,l(r),d(null),p(null),i())};if(zO(r,``).length<2){o();return}let s=r.crumbs.at(-2);s===void 0?o():(ce(s.path).then(e=>{if(n!==ne.current)return;let t=BO(e),s=e=>t===`\\`?e.toLowerCase():e,c=e.entries.find(e=>s(e.path)===s(r.path));c===void 0?o():(a=!0,l(e),d(c),p(r),i())},()=>{o()}),t.closeEditor&&window.setTimeout(o,LO))},e=>{n===ne.current&&(h(!1),t.announce&&x(FO(e)))})},[se,ce]),me=(0,P.useCallback)(e=>{pe(e,{closeEditor:!0,announce:!0})},[pe]),N=(0,P.useRef)(!1),he=(0,P.useRef)(!1),ge=(0,P.useRef)(null),_e=(0,P.useRef)(null),ve=(0,P.useCallback)(e=>{let{seq:t,scan:n}=se(e.path);S!==null&&(N.current=!0),C(null),d(e),p(null),h(!0),x(null),n.then(e=>{t===ne.current&&(p(e),h(!1))},e=>{t===ne.current&&(h(!1),x(FO(e)),d(null),he.current=!0)})},[se,S]),ye=(0,P.useCallback)(e=>{pe(e,{closeEditor:!1,announce:!1})},[pe]),be=(0,P.useCallback)(()=>{oe(),h(!1),C(null),x(null),f===null&&d(null),c===null&&me()},[oe,f,c,me]),xe=(0,P.useCallback)(e=>{f!==null&&(l(f),ve(e))},[f,ve]);(0,P.useEffect)(()=>{re.current+=1,e?(l(null),d(null),p(null),k(!1),T(!1),me()):(oe(),h(!1),x(null),C(null),D(null),te(null),N.current=!1,he.current=!1)},[e,me,oe]);let Se=u?.path??c?.path??null,Ce=u?.name??(c===null?``:zO(c,s(`browser.home`)).at(-1)?.name??c.path),we=()=>{if(Se===null||E===null||O)return;let e=E;if(e.trim()===``)return;k(!0),te(null);let t=re.current;r(Se,e).then(n=>{if(t!==re.current)return;k(!1),D(null);let{seq:r,scan:i}=se(Se);h(!0),x(null),i.then(t=>{r===ne.current&&(l(t),h(!1),ve({name:e,path:n,hidden:!1}))},e=>{r===ne.current&&(h(!1),x(FO(e)))})},e=>{t===re.current&&(k(!1),te(FO(e)))})};(0,P.useEffect)(()=>{if(!m){_(!1);return}let e=window.setTimeout(()=>{_(!0)},IO);return()=>{window.clearTimeout(e)}},[m,v]),(0,P.useEffect)(()=>{if(S===null)return;let e=window.setTimeout(()=>{if(le.current)return;let e=ue.current.child??ue.current.parent;if(e===null)return;let{directory:t,tail:n}=UO(e,S,de.current);t!==null&&n===null&&ye(t)},RO);return()=>{window.clearTimeout(e)}},[S,ye]);let Te=f??c,Ee=Te===null||S===null?null:UO(Te,S,de.current).tail,De=Te===null?[]:zO(Te,s(`browser.home`)),Oe=De.at(-1)?.path;(0,P.useEffect)(()=>{let e=ie.current;e!==null&&(e.scrollLeft=e.scrollWidth)},[Oe]);let ke=(0,P.useRef)(null),Ae=f?.path;if((0,P.useEffect)(()=>{let e=ke.current;e!==null&&Ae!==void 0&&(e.scrollLeft=e.scrollWidth)},[Ae]),(0,P.useEffect)(()=>{if(fe.current&&(fe.current=!1,document.activeElement===document.body&&ge.current?.focus()),S===null){if(N.current){N.current=!1,he.current=!1;let e=ke.current;if(e===null)return;let t=e.querySelector(`button[aria-current="true"]`);if(t===null)return;t.focus()}else if(he.current){if(he.current=!1,document.activeElement!==document.body)return;let e=_e.current;if(e===null)return;e.focus()}}}),!e)return null;let je=u!==null,Me=o||E!==null,Ne=S!==null;return(0,F.jsxs)(OO,{open:e,onClose:()=>{E===null&&!o&&a()},title:s(`browser.title`),className:n(PO.dialog),headless:!0,children:[(0,F.jsxs)(`div`,{className:PO.editorScope,onKeyDown:e=>{e.key===`Escape`&&S!==null&&(e.stopPropagation(),he.current=document.activeElement===ge.current,be())},onBlur:e=>{if(S===null||!document.hasFocus())return;let t=e.currentTarget.closest(`[role="dialog"]`);t!==null&&(e.relatedTarget instanceof Node&&t.contains(e.relatedTarget)||(he.current=!1,be()))},children:[(0,F.jsxs)(`div`,{className:PO.header,children:[(0,F.jsx)(`h2`,{className:PO.title,children:s(`browser.title`)}),(0,F.jsx)(`div`,{className:PO.crumbBar,children:S===null?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`span`,{className:PO.crumbTrail,role:`navigation`,ref:ie,children:De.map((e,t)=>(0,F.jsxs)(`span`,{className:PO.crumbSeat,children:[t>0&&(0,F.jsx)(lt,{size:12,className:PO.crumbChevron}),(0,F.jsx)(`button`,{type:`button`,className:PO.crumb,disabled:Me,onClick:()=>{me(e.path)},children:e.name})]},e.path))}),(0,F.jsx)(`button`,{type:`button`,className:PO.crumbEditZone,"aria-label":s(`browser.editPath`),title:s(`browser.editPath`),disabled:Me,ref:_e,onClick:()=>{if(oe(),h(!1),le.current=!1,c===null){C(``);return}let e=u?.path??c.path,t=BO(c);C(e.endsWith(t)?e:`${e}${t}`)},children:(0,F.jsx)(pt,{size:14,className:PO.crumbEditGlyph})})]}):(0,F.jsx)(`input`,{className:PO.pathInput,value:S,"aria-label":s(`browser.editPath`),autoFocus:!0,ref:ge,disabled:Me,onChange:e=>{oe(),h(!1),le.current=!1,C(e.target.value)},...ae,onKeyDown:e=>{e.key===`Enter`&&!j.current&&(e.preventDefault(),S.trim()!==``&&(he.current=!0,le.current=!0,me(S)))}})})]}),(0,F.jsxs)(`div`,{className:PO.content,children:[(0,F.jsxs)(`div`,{className:PO.millerRow,ref:ke,children:[c!==null&&(0,F.jsx)(GO,{entries:c.entries,selectedPath:u?.path??null,busy:Me,onPick:ve,showHidden:w,filterPrefix:f===null?Ee:null,pathEditing:Ne}),je&&(0,F.jsx)(`span`,{className:PO.divider}),je&&f!==null&&(0,F.jsx)(GO,{entries:f.entries,selectedPath:null,busy:Me,onPick:xe,showHidden:w,filterPrefix:Ee,pathEditing:Ne})]}),m&&g&&(0,F.jsx)(`div`,{className:n(PO.status,PO.loadingFloat),role:`status`,children:s(`browser.loading`)}),(c?.truncated===!0||f?.truncated===!0)&&(0,F.jsx)(`div`,{className:PO.status,role:`status`,children:s(`browser.truncated`)}),b!==null&&(0,F.jsx)(`div`,{className:PO.error,role:`alert`,children:b})]}),(0,F.jsxs)(`div`,{className:PO.footerBar,children:[(0,F.jsx)(EO,{variant:`outline`,icon:(0,F.jsx)(ot,{size:14}),disabled:c===null||m||Me||Ne,onClick:()=>{D(``),te(null)},children:s(`browser.newFolder`)}),(0,F.jsxs)(`button`,{type:`button`,className:n(PO.showHiddenToggle,w&&PO.showHiddenToggleActive),"aria-pressed":w,disabled:Me,onMouseDown:Ne?e=>{e.preventDefault()}:void 0,onClick:()=>{T(e=>!e)},children:[s(`browser.showHidden`),w&&(0,F.jsx)(st,{size:14})]}),(0,F.jsx)(`span`,{className:PO.footerGap}),(0,F.jsx)(EO,{variant:`outline`,className:n(PO.footerAction),disabled:Me,onClick:a,children:s(`browser.cancel`)}),(0,F.jsx)(EO,{variant:`primary`,className:n(PO.footerAction),disabled:Se===null||m||Me||Ne,onClick:()=>{Se!==null&&i(Se)},children:s(`browser.open`)})]})]}),(0,F.jsx)(OO,{open:E!==null,onClose:()=>{O||D(null)},title:s(`browser.newFolder`),className:n(PO.createDialog),headless:!0,children:(0,F.jsxs)(`div`,{className:PO.createBody,children:[(0,F.jsx)(`h3`,{className:PO.createTitle,children:s(`browser.newFolder`)}),(0,F.jsx)(`p`,{className:PO.createIn,children:s(`browser.createIn`,{name:Ce})}),(0,F.jsx)(`input`,{className:PO.createInput,value:E??``,"aria-label":s(`browser.folderName`),placeholder:s(`browser.untitledFolder`),autoFocus:!0,disabled:O,onChange:e=>{D(e.target.value)},...ae,onKeyDown:e=>{e.key===`Enter`&&!j.current&&(e.preventDefault(),we()),e.key===`Escape`&&(e.stopPropagation(),O||D(null))}}),ee!==null&&(0,F.jsx)(`div`,{className:PO.error,role:`alert`,children:ee}),(0,F.jsxs)(`div`,{className:PO.createActions,children:[(0,F.jsx)(EO,{variant:`outline`,disabled:O,onClick:()=>{D(null)},children:s(`browser.cancel`)}),(0,F.jsx)(EO,{variant:`primary`,disabled:O||E===null||E.trim()===``,onClick:we,children:s(`browser.create`)})]})]})})]})}var qO={root:`_root_nvze1_1`,rail:`_rail_nvze1_13`,iconButton:`_iconButton_nvze1_17`,searchButton:`_searchButton_nvze1_33`,clearButton:`_clearButton_nvze1_34`,sectionHeader:`_sectionHeader_nvze1_45`,sectionLabel:`_sectionLabel_nvze1_65`,sectionLabelHidden:`_sectionLabelHidden_nvze1_82`,searchSlot:`_searchSlot_nvze1_91`,searchSlotExpanded:`_searchSlotExpanded_nvze1_105`,headerActions:`_headerActions_nvze1_110`,headerActionsHidden:`_headerActionsHidden_nvze1_126`,search:`_search_nvze1_33`,searchExpanded:`_searchExpanded_nvze1_160`,searchInput:`_searchInput_nvze1_199`,listArea:`_listArea_nvze1_285`,treeBody:`_treeBody_nvze1_305`,fade:`_fade_nvze1_315`,wide:`_wide_nvze1_326`,"wide-in":`_wide-in_nvze1_1`,list:`_list_nvze1_285`,flatList:`_flatList_nvze1_356`,searchTree:`_searchTree_nvze1_357`,groupSection:`_groupSection_nvze1_358`,searchStatus:`_searchStatus_nvze1_362`,searchWarning:`_searchWarning_nvze1_363`,listTopDropIndicator:`_listTopDropIndicator_nvze1_383`,workspaceDropBefore:`_workspaceDropBefore_nvze1_384`,workspaceDropAfter:`_workspaceDropAfter_nvze1_385`,listTopDropActive:`_listTopDropActive_nvze1_419`,sessionOverflowButton:`_sessionOverflowButton_nvze1_431`,empty:`_empty_nvze1_453`,renameInput:`_renameInput_nvze1_460`,renameError:`_renameError_nvze1_479`,deleteAction:`_deleteAction_nvze1_486`,deleteStatus:`_deleteStatus_nvze1_490`},JO={projectRow:`_projectRow_mhb10_1`,sessionRow:`_sessionRow_mhb10_2`,selected:`_selected_mhb10_18`,searchResultRow:`_searchResultRow_mhb10_22`,searchResultHeading:`_searchResultHeading_mhb10_46`,searchResultTitle:`_searchResultTitle_mhb10_52`,searchResultMeta:`_searchResultMeta_mhb10_63`,searchResultWorkspace:`_searchResultWorkspace_mhb10_71`,searchResultSnippet:`_searchResultSnippet_mhb10_72`,rowActions:`_rowActions_mhb10_99`,"row-in":`_row-in_mhb10_1`,title:`_title_mhb10_112`,flatSessionRowWithoutStatus:`_flatSessionRowWithoutStatus_mhb10_116`,slot:`_slot_mhb10_124`,visuallyHidden:`_visuallyHidden_mhb10_134`,folderActive:`_folderActive_mhb10_143`,chevron:`_chevron_mhb10_149`,folder:`_folder_mhb10_143`,arrow:`_arrow_mhb10_154`,arrowOpen:`_arrowOpen_mhb10_158`,projectText:`_projectText_mhb10_162`,renameInput:`_renameInput_mhb10_179`,meta:`_meta_mhb10_195`,time:`_time_mhb10_204`,scheduleIndicator:`_scheduleIndicator_mhb10_211`,searchScheduleIndicator:`_searchScheduleIndicator_mhb10_222`,dot:`_dot_mhb10_227`,menuOpen:`_menuOpen_mhb10_242`,dropBefore:`_dropBefore_mhb10_261`,dropAfter:`_dropAfter_mhb10_262`,hoverContent:`_hoverContent_mhb10_302`,hoverTitle:`_hoverTitle_mhb10_308`,hoverPath:`_hoverPath_mhb10_315`,hoverTime:`_hoverTime_mhb10_322`,hoverStatus:`_hoverStatus_mhb10_328`,iconButton:`_iconButton_mhb10_337`},YO=(e,t)=>({"browser.title":r(`选择工作区目录`,`Select workspace directory`),"browser.home":r(`主目录`,`Home`),"browser.newFolder":r(`新建文件夹`,`New folder`),"browser.folderName":r(`文件夹名称`,`Folder name`),"browser.createIn":r(`在"{name}"中新建文件夹`,`Create folder in "{name}"`),"browser.untitledFolder":r(`未命名文件夹`,`Untitled folder`),"browser.create":r(`创建`,`Create`),"browser.cancel":r(`取消`,`Cancel`),"browser.open":r(`打开`,`Open`),"browser.editPath":r(`编辑路径`,`Edit path`),"browser.loading":r(`加载中…`,`Loading…`),"browser.truncated":r(`文件夹过多,仅显示开头部分。`,`Too many folders; only the first few are shown.`),"browser.showHidden":r(`显示隐藏文件`,`Show hidden files`)}[e]??e).replace(/\{(\w+)\}/g,(e,n)=>t?.[n]??``);function XO({wide:e,navigationBusy:t=!1,connected:n=!0,expandSidebar:i,session:a,workspaces:o,onAdd:s,directoryPickerKind:c,pickDirectory:u,listDirectory:d,createDirectory:f,onRemove:p,onSelectSession:m,onNewSession:h,onRenameSession:g,onDeleteSession:_}){let v=l(),[y,b]=(0,P.useState)(Date.now),[x,S]=(0,P.useState)(null),[C,w]=(0,P.useState)(null),[T,E]=(0,P.useState)(null),[D,O]=(0,P.useState)(``),[k,ee]=(0,P.useState)(null),te=(0,P.useRef)(null);(0,P.useEffect)(()=>{if(!T)return;let e=requestAnimationFrame(()=>{te.current?.focus(),te.current?.select()});return()=>cancelAnimationFrame(e)},[T]),(0,P.useEffect)(()=>{if(!e){S(null),w(null);return}b(Date.now());let t=window.setInterval(()=>b(Date.now()),6e4);return()=>window.clearInterval(t)},[e]);let[ne,A]=(0,P.useState)(!1),[re,ie]=(0,P.useState)(!1),j=re||t,ae=j||!n,oe=(0,P.useId)(),M=(0,P.useRef)(null),[se,ce]=(0,P.useState)(null),[le,ue]=(0,P.useState)(``),[de,fe]=(0,P.useState)(``),[pe,me]=(0,P.useState)(!1),[N,he]=(0,P.useState)(``);(0,P.useEffect)(()=>{he(``)},[a?.sessionId]);let[ge,_e]=(0,P.useState)(new Set);(0,P.useEffect)(()=>{o.activeId&&_e(e=>e.has(o.activeId)?e:new Set([...e,o.activeId]))},[o.activeId,a?.sessionId]),(0,P.useEffect)(()=>{M.current?.querySelector(`[aria-current="page"]`)?.scrollIntoView({block:`nearest`})},[e,a?.sessionId,ge]);let ve=(0,P.useRef)(null),ye=(0,P.useRef)(null),be=N.trim().toLocaleLowerCase(),xe=()=>{he(``),me(!1),ve.current?.focus()},Se=o.items.filter(e=>!be||e.title.toLocaleLowerCase().includes(be)||e.path.toLocaleLowerCase().includes(be)||o.sessions.some(t=>t.workspaceId===e.id&&t.name.toLocaleLowerCase().includes(be))),Ce=async e=>{if(!ae){ie(!0),ue(``);try{await e()}catch(e){ue(e instanceof Error?e.message:r(`操作失败`,`Operation failed`))}finally{ie(!1)}}},we=async e=>{ie(!0);try{await s(e,!1),A(!1)}catch(e){A(!1),fe(e instanceof Error?e.message:String(e))}finally{ie(!1)}},Te=async()=>{if(c!==null){if(e||i(),ue(``),c===`browse`)A(!0);else{ie(!0);try{let e=await u();e!==null&&await we(e)}catch(e){fe(e instanceof Error?e.message:String(e))}finally{ie(!1)}}}};return(0,F.jsxs)(`div`,{ref:M,"aria-busy":j,className:`${qO.root} ${e?``:qO.rail}`,children:[(0,F.jsxs)(`div`,{className:qO.sectionHeader,children:[e&&(0,F.jsx)(`span`,{className:`${qO.sectionLabel} ${qO.wide} ${pe?qO.sectionLabelHidden:``}`,children:r(`工作区`,`Workspaces`)}),e&&(0,F.jsx)(`div`,{className:`${qO.searchSlot} ${pe?qO.searchSlotExpanded:``}`,children:(0,F.jsxs)(`div`,{className:`${qO.search} ${pe?qO.searchExpanded:``}`,onClick:()=>{me(!0),ye.current?.focus()},children:[(0,F.jsx)(`button`,{ref:ve,type:`button`,className:qO.searchButton,"aria-label":r(`搜索工作区和会话`,`Search workspaces and sessions`),"aria-expanded":pe,onClick:()=>{me(!0),ye.current?.focus()},children:(0,F.jsx)(tt,{size:pe?11:14})}),(0,F.jsx)(`input`,{ref:ye,className:qO.searchInput,type:`search`,"aria-label":r(`按名称或工作区路径搜索`,`Search by name or workspace path`),placeholder:r(`按名称或工作区路径搜索`,`Search by name or workspace path`),maxLength:120,value:N,tabIndex:pe?0:-1,onChange:e=>he(e.target.value),onKeyDown:e=>{e.key===`Escape`&&(e.stopPropagation(),xe())}}),pe&&(0,F.jsx)(`button`,{type:`button`,className:qO.clearButton,"aria-label":r(`关闭搜索`,`Close search`),onClick:e=>{e.stopPropagation(),xe()},children:(0,F.jsx)(dt,{})})]})}),(0,F.jsx)(`div`,{className:`${qO.headerActions} ${e&&pe?qO.headerActionsHidden:``}`,children:(0,F.jsx)(`button`,{type:`button`,className:qO.iconButton,"aria-label":r(`添加工作区`,`Add workspace`),title:r(`添加工作区`,`Add workspace`),disabled:ae||c===null,onClick:()=>{Te()},children:(0,F.jsx)(bt,{size:e?16:18})})})]}),e&&(0,F.jsx)(`div`,{className:qO.listArea,children:(0,F.jsx)(`div`,{className:qO.treeBody,children:(0,F.jsxs)(`div`,{className:qO.list,role:`list`,"aria-label":r(`工作区`,`Workspaces`),children:[Se.map(e=>{let t=e.id===o.activeId,n=e.available===!1,i=ge.has(e.id)||!!be;return(0,F.jsxs)(`div`,{className:kO.group,role:`listitem`,children:[(0,F.jsxs)(`div`,{className:kO.workspaceLine,"data-menu-open":x===e.id||void 0,children:[(0,F.jsxs)(`button`,{type:`button`,className:`${JO.projectRow} ${kO.workspaceButton}`,"aria-expanded":i,"aria-controls":`${oe}-${e.id}`,title:e.path,disabled:j,onContextMenu:t=>{ae||(t.preventDefault(),t.stopPropagation(),w(null),S(e.id))},onClick:()=>_e(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n}),children:[(0,F.jsxs)(`span`,{className:JO.slot,"aria-hidden":`true`,children:[(0,F.jsx)(`span`,{"data-workspace-leading":`folder`,className:`${kO.folder} ${t?kO.folderActive:``}`,children:i?(0,F.jsx)(xt,{size:16}):(0,F.jsx)(St,{size:16})}),(0,F.jsx)(`span`,{"data-workspace-leading":`chevron`,className:`${kO.chevron} ${i?kO.chevronOpen:``}`,children:(0,F.jsx)(ct,{size:14})})]}),(0,F.jsx)(`span`,{className:`${JO.title} ${kO.workspaceTitle}`,children:e.title}),n&&(0,F.jsx)(`span`,{className:kO.unavailable,children:r(`不可用`,`Unavailable`)})]}),(0,F.jsxs)(`span`,{className:kO.rowActions,"data-workspace-actions":!0,children:[(0,F.jsx)(AO,{title:e.title,active:t,disabled:ae,open:x===e.id,onOpenChange:t=>S(t?e.id:null),onRemove:()=>{ue(``),ce({id:e.id,title:e.title})}}),(0,F.jsx)(`button`,{type:`button`,className:kO.rowAction,title:n?r(`目录不可用,请恢复目录或移除后重新添加`,`Directory unavailable; restore it or remove and add the workspace again`):r(`新建会话`,`New session`),"aria-label":r(`在 ${e.title} 新建会话`,`Create a session in ${e.title}`),disabled:ae||n,onClick:()=>{Ce(async()=>{await h(e.id),he(``),_e(t=>new Set([...t,e.id]))})},children:(0,F.jsx)(et,{size:16})})]})]}),(0,F.jsxs)(`div`,{id:`${oe}-${e.id}`,role:`group`,"aria-label":e.title,hidden:!i,children:[i&&o.sessions.filter(t=>t.workspaceId===e.id&&(!be||e.title.toLocaleLowerCase().includes(be)||e.path.toLocaleLowerCase().includes(be)||t.name.toLocaleLowerCase().includes(be))).map(i=>{let o=t&&a?.sessionId===i.id,s=a?.sessionId===i.id?!a.idle:i.idle===!1,c=i.name||r(`新会话`,`New chat`),l={workspaceId:e.id,id:i.id,path:i.path,name:i.name,running:s};return(0,F.jsxs)(`div`,{className:kO.sessionLine,"data-menu-open":C===i.id||void 0,children:[(0,F.jsxs)(`button`,{type:`button`,className:`${JO.sessionRow} ${kO.sessionButton} ${o?JO.selected:``}`,title:c,"aria-label":c,"aria-describedby":`${oe}-${i.id}-status`,"aria-current":o?`page`:void 0,disabled:ae||n,onContextMenu:e=>{ae||n||(e.preventDefault(),e.stopPropagation(),S(null),w(i.id))},onClick:()=>{Ce(()=>m(e.id,i.id,i.path))},children:[(0,F.jsx)(`span`,{className:JO.slot,children:s&&(0,F.jsx)($e,{state:`ongoing`})}),(0,F.jsx)(`span`,{className:`${JO.title} ${i.name?``:kO.untitled}`,children:c}),(0,F.jsx)(`time`,{className:kO.sessionTime,dateTime:i.modified,title:i.modified,children:NO(i.modified,y,v)}),(0,F.jsx)(`span`,{id:`${oe}-${i.id}-status`,className:JO.visuallyHidden,children:s?r(`运行中`,`Running`):r(`空闲`,`Idle`)})]}),(0,F.jsx)(`span`,{className:kO.rowActions,children:(0,F.jsx)(jO,{title:c,disabled:ae||n,open:C===i.id,onOpenChange:e=>w(e?i.id:null),onRename:()=>{ue(``),O(i.name),E(l)},onDelete:()=>{ue(``),ee(l)}})})]},i.id)}),i&&!be&&!o.sessions.some(t=>t.workspaceId===e.id)&&(0,F.jsx)(`p`,{className:qO.empty,children:r(`还没有会话,创建新会话开始`,`No sessions yet. Create a session to start.`)})]})]},e.id)}),Se.length===0&&(0,F.jsxs)(`p`,{className:qO.empty,role:`status`,children:[be?r(`没有找到匹配的工作区或会话`,`No matching workspaces or sessions`):r(`添加工作区,开始管理对话`,`Add a workspace to start organizing conversations`),be&&(0,F.jsx)(`button`,{type:`button`,className:qO.sessionOverflowButton,onClick:xe,children:r(`清除搜索`,`Clear search`)})]}),j&&(0,F.jsx)(`p`,{className:qO.searchStatus,role:`status`,children:r(`正在处理…`,`Working…`)}),le&&!ne&&(0,F.jsx)(`p`,{className:kO.error,role:`alert`,children:le})]})})}),(0,F.jsxs)(OO,{open:se!==null,onClose:()=>{j||ce(null)},title:r(`移除工作区?`,`Remove workspace?`),closeLabel:r(`关闭`,`Close`),footer:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(EO,{variant:`outline`,disabled:j,onClick:()=>ce(null),children:r(`取消`,`Cancel`)}),(0,F.jsx)(EO,{variant:`primary`,disabled:ae,onClick:()=>{se&&Ce(async()=>{await p(se.id),ce(null)})},children:r(`从列表移除`,`Remove from list`)})]}),children:[(0,F.jsx)(`p`,{children:se?.title}),(0,F.jsx)(`p`,{children:r(`仅从侧栏移除,不删除目录、文件或会话历史。`,`Only removes it from the sidebar. Directories, files and session history are not deleted.`)}),le&&(0,F.jsx)(`p`,{role:`alert`,children:le})]}),(0,F.jsxs)(OO,{open:T!==null,onClose:()=>{j||E(null)},title:r(`重命名会话`,`Rename chat`),closeLabel:r(`关闭`,`Close`),footer:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(EO,{variant:`outline`,disabled:j,onClick:()=>E(null),children:r(`取消`,`Cancel`)}),(0,F.jsx)(EO,{variant:`primary`,type:`submit`,form:`${oe}-rename`,disabled:ae,children:r(`保存`,`Save`)})]}),children:[(0,F.jsx)(`form`,{id:`${oe}-rename`,onSubmit:e=>{e.preventDefault(),T&&Ce(async()=>{await g(T.workspaceId,T.id,T.path,D),E(null)})},children:(0,F.jsx)(`input`,{className:kO.renameInput,"aria-label":r(`会话名称`,`Chat name`),placeholder:r(`留空则使用第一条消息`,`Leave empty to use the first message`),maxLength:120,ref:te,value:D,onChange:e=>O(e.target.value)})}),le&&(0,F.jsx)(`p`,{role:`alert`,children:le})]}),(0,F.jsxs)(OO,{open:k!==null,onClose:()=>{j||ee(null)},title:r(`删除会话?`,`Delete chat?`),closeLabel:r(`关闭`,`Close`),footer:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(EO,{variant:`outline`,disabled:j,onClick:()=>ee(null),children:r(`取消`,`Cancel`)}),(0,F.jsx)(EO,{variant:`primary`,disabled:ae||k?.running,onClick:()=>{k&&Ce(async()=>{await _(k.workspaceId,k.id,k.path),ee(null)})},children:r(`删除`,`Delete`)})]}),children:[(0,F.jsx)(`p`,{children:k?.name||r(`新会话`,`New chat`)}),(0,F.jsx)(`p`,{children:k?.running?r(`Pi 正在运行,请等待当前回复结束后再删除。`,`Pi is still working. Wait for the reply to finish before deleting.`):r(`会话会从列表中移除,文件移到 Pi 数据目录的 pi-web/trash 中,可手动恢复。项目文件不受影响。`,`The chat leaves the list and its file moves to pi-web/trash in the Pi data folder, where you can restore it by hand. Project files are not affected.`)}),le&&(0,F.jsx)(`p`,{role:`alert`,children:le})]}),(0,F.jsx)(KO,{open:ne,busy:j,listDirectory:d,createDirectory:f,onOpen:e=>{we(e)},onClose:()=>{j||A(!1)},t:YO}),(0,F.jsx)(OO,{open:!!de,onClose:()=>fe(``),title:r(`无法添加工作区`,`Could not add workspace`),closeLabel:r(`关闭`,`Close`),footer:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(EO,{variant:`outline`,onClick:()=>fe(``),children:r(`取消`,`Cancel`)}),(0,F.jsx)(EO,{variant:`primary`,onClick:()=>{fe(``),Te()},children:r(`重新选择`,`Choose again`)})]}),children:(0,F.jsx)(`div`,{role:`alert`,children:de})})]})}function ZO(e){let t=e.trim();if(!t)return;let n=/^(\d+(?:\.\d+)?)([km])?$/i.exec(t);if(!n)return NaN;let r=n[2]?.toLowerCase(),i=r===`m`?1e6:r===`k`?1e3:1,a=Number(n[1])*i,o=Math.round(a);return Math.abs(a-o)<1e-6?o:a}function QO(e){return e===void 0?``:!Number.isInteger(e)||e<=0?String(e):e%1e6==0?`${e/1e6}M`:e%1e3==0?`${e/1e3}K`:String(e)}function $O({model:e,position:t,onSave:n,onRemove:i,onCancel:a}){let[o,s]=(0,P.useState)(e.id),[c,l]=(0,P.useState)(e.name??``),[u,d]=(0,P.useState)(QO(e.contextWindow)),[f,p]=(0,P.useState)(QO(e.maxTokens)),[m,h]=(0,P.useState)(e.input?.length?e.input:[`text`]),[g,_]=(0,P.useState)(!e.id),[v,y]=(0,P.useState)(!1),[b,x]=(0,P.useState)(!1),[S,C]=(0,P.useState)(``),w=!e.id,T=!w&&(e.source===`custom`||e.overridden),E=async()=>{let e=ZO(u),t=ZO(f);if(!o.trim()||[e,t].some(e=>e!==void 0&&(!Number.isSafeInteger(e)||e<=0)))C(r(`请填写模型 ID,并使用正整数或 K/M 单位填写容量。`,`Enter a model ID and positive token counts, optionally with K/M suffixes.`));else{x(!0),C(``);try{await n({id:o.trim(),...c.trim()?{name:c.trim()}:{},...e===void 0?{}:{contextWindow:e},...t===void 0?{}:{maxTokens:t},input:m})}catch(e){C(e instanceof Error?e.message:r(`保存失败`,`Could not save`))}finally{x(!1)}}},D=async()=>{x(!0),C(``);try{await i()}catch(e){C(e instanceof Error?e.message:r(`操作失败`,`Action failed`)),y(!1)}finally{x(!1)}},O=e=>{h(t=>{let n=t.includes(e)?t.filter(t=>t!==e):[...t,e];return n.length?n:t})};return(0,F.jsxs)(`div`,{className:`pi-model-entry`,children:[(0,F.jsxs)(`div`,{className:`pi-model-row`,children:[(0,F.jsx)(`input`,{"aria-label":`${r(`模型 ID`,`Model ID`)} ${t}`,placeholder:r(`模型 ID`,`Model ID`),value:o,disabled:b||!w&&e.source===`builtin`,onFocus:()=>_(!0),onChange:e=>s(e.target.value)}),(0,F.jsx)(`input`,{"aria-label":`${r(`显示名称`,`Display name`)} ${t}`,placeholder:r(`显示名称`,`Display name`),value:c,disabled:b,onFocus:()=>_(!0),onChange:e=>l(e.target.value)}),(0,F.jsx)(`button`,{type:`button`,"aria-label":`${r(`模型参数`,`Model settings`)} ${t}`,"aria-expanded":g,onClick:()=>_(!g),children:g?`⌄`:`›`})]}),g&&(0,F.jsxs)(`div`,{className:`pi-model-details`,children:[(0,F.jsxs)(`label`,{children:[r(`上下文窗口`,`Context window`),(0,F.jsx)(`input`,{"aria-label":`${r(`上下文窗口`,`Context window`)} ${t}`,inputMode:`decimal`,placeholder:`128K`,value:u,disabled:b,onChange:e=>d(e.target.value)})]}),(0,F.jsxs)(`label`,{children:[r(`最大输出 token 数`,`Max output tokens`),(0,F.jsx)(`input`,{"aria-label":`${r(`最大输出 token 数`,`Max output tokens`)} ${t}`,inputMode:`decimal`,placeholder:`16K`,value:f,disabled:b,onChange:e=>p(e.target.value)})]}),(0,F.jsxs)(`fieldset`,{className:`pi-model-input-types`,children:[(0,F.jsx)(`legend`,{children:r(`输入类型`,`Input types`)}),(0,F.jsxs)(`label`,{children:[(0,F.jsx)(`input`,{type:`checkbox`,checked:m.includes(`text`),disabled:b||m.length===1&&m.includes(`text`),onChange:()=>O(`text`)}),r(`文本`,`Text`)]}),(0,F.jsxs)(`label`,{children:[(0,F.jsx)(`input`,{type:`checkbox`,checked:m.includes(`image`),disabled:b||m.length===1&&m.includes(`image`),onChange:()=>O(`image`)}),r(`图片`,`Image`)]})]}),(0,F.jsxs)(`div`,{className:`pi-model-actions`,children:[(0,F.jsx)(`button`,{type:`button`,disabled:b,onClick:()=>{E()},children:b?r(`保存中…`,`Saving…`):r(`保存模型`,`Save model`)}),w&&a&&(0,F.jsx)(`button`,{type:`button`,disabled:b,onClick:a,children:r(`取消`,`Cancel`)}),T&&(0,F.jsx)(`button`,{type:`button`,disabled:b,onClick:()=>y(!v),children:e.source===`custom`?r(`移除模型`,`Remove model`):r(`恢复默认`,`Restore default`)})]}),v&&(0,F.jsxs)(`div`,{className:`pi-model-confirm`,children:[(0,F.jsx)(`span`,{children:e.source===`custom`?r(`从配置中移除这个模型?`,`Remove this model from configuration?`):r(`撤销这个模型的自定义参数?`,`Discard this model’s custom settings?`)}),(0,F.jsx)(`button`,{type:`button`,disabled:b,onClick:()=>{D()},children:r(`确认`,`Confirm`)}),(0,F.jsx)(`button`,{type:`button`,disabled:b,onClick:()=>y(!1),children:r(`取消`,`Cancel`)})]}),S&&(0,F.jsx)(`p`,{className:`pi-settings-error`,role:`alert`,children:S})]})]})}function ek({providerId:e,getModels:t,updateModel:n}){let[i,a]=(0,P.useState)(null),[o,s]=(0,P.useState)(``),[c,l]=(0,P.useState)(``),[u,d]=(0,P.useState)(!1),f=async()=>{s(``);try{a(await t(e))}catch(e){throw s(e instanceof Error?e.message:r(`无法读取模型目录`,`Could not load model catalog`)),e}};(0,P.useEffect)(()=>{f().catch(()=>{})},[e]);let p=async t=>{await n(e,t),d(!1),await f().catch(()=>{})},m=i?.models.filter(e=>`${e.id} ${e.name??``}`.toLocaleLowerCase().includes(c.toLocaleLowerCase()))??[];return(0,F.jsxs)(`section`,{className:`pi-provider-models`,"aria-label":r(`模型目录`,`Model catalog`),children:[(0,F.jsxs)(`div`,{className:`pi-provider-models-head`,children:[(0,F.jsx)(`strong`,{children:r(`模型目录`,`Model catalog`)}),(0,F.jsxs)(`span`,{children:[i?.models.length??0,` `,r(`个模型`,`models`)]})]}),i?.baseUrl&&(0,F.jsxs)(`p`,{className:`pi-provider-models-endpoint`,title:i.baseUrl,children:[r(`API 地址`,`API URL`),`: `,i.baseUrl]}),o&&(0,F.jsxs)(`p`,{className:`pi-settings-error`,role:`alert`,children:[o,` `,i&&(0,F.jsx)(`button`,{type:`button`,onClick:()=>{f().catch(()=>{})},children:r(`重试读取`,`Retry`)})]}),i?(0,F.jsxs)(F.Fragment,{children:[i.models.length>5&&(0,F.jsx)(`input`,{className:`pi-model-search`,type:`search`,"aria-label":r(`搜索模型`,`Search models`),placeholder:r(`搜索模型`,`Search models`),value:c,onChange:e=>l(e.target.value)}),(0,F.jsx)(`div`,{className:`pi-model-list`,children:m.map((e,t)=>(0,F.jsx)($O,{model:e,position:t+1,onSave:t=>p({action:`save`,originalId:e.id,model:t}),onRemove:()=>p({action:`remove`,id:e.id})},`${e.id}:${e.name}:${e.contextWindow}:${e.maxTokens}:${e.overridden}`))}),m.length===0&&!u&&(0,F.jsx)(`p`,{className:`pi-provider-models-empty`,children:r(`没有匹配的模型`,`No matching models`)}),u&&(0,F.jsx)($O,{model:{id:``,source:`custom`,overridden:!1},position:i.models.length+1,onSave:e=>p({action:`save`,model:e}),onRemove:async()=>d(!1),onCancel:()=>d(!1)},`new`),!u&&(0,F.jsx)(`button`,{type:`button`,className:`pi-model-add`,onClick:()=>d(!0),children:r(`+ 添加模型`,`+ Add model`)})]}):o?(0,F.jsx)(`button`,{type:`button`,className:`pi-model-add`,onClick:()=>{f().catch(()=>{})},children:r(`重试读取`,`Retry`)}):(0,F.jsx)(`p`,{role:`status`,children:r(`正在读取模型…`,`Loading models…`)})]})}var tk={id:``,name:``,baseUrl:``,api:`openai-completions`,modelId:``};function nk(e){try{let t=new URL(e);return t.protocol===`https:`||t.protocol===`http:`?t.href:null}catch{return null}}function rk(){let e=null;try{return e=window.open(`about:blank`,`_blank`),e&&(e.opener=null,e.document.title=r(`正在准备授权页面`,`Preparing sign-in`),e.document.body.textContent=r(`正在准备授权页面…`,`Preparing sign-in…`)),e}catch{return e?.close(),null}}function ik({provider:e,configured:t,busy:n,getProviderModels:i,updateProviderModel:a,onConnect:o}){let[s,c]=(0,P.useState)(``),[l,u]=(0,P.useState)(``),[d,f]=(0,P.useState)(``),[p,m]=(0,P.useState)(!0),[h,g]=(0,P.useState)(!1),[_,v]=(0,P.useState)(``);(0,P.useEffect)(()=>{let t=!0;return m(!0),i(e.id).then(e=>{t&&(u(e.baseUrl??``),f(e.baseUrl??``),m(!1))}).catch(e=>{t&&(m(!1),v(e instanceof Error?e.message:r(`无法读取 API 地址`,`Could not load API URL`)))}),()=>{t=!1}},[e.id]);let y=async()=>{let n=s.trim(),i=l.trim();if(n||t){if(i&&!nk(i))v(r(`请输入有效的 http 或 https 地址。`,`Enter a valid HTTP or HTTPS URL.`));else{g(!0),v(``);try{i!==d&&(await a(e.id,{action:`base_url`,baseUrl:i||null}),f(i)),n&&(c(``),await o(n))}catch(e){v(e instanceof Error?e.message:r(`保存失败`,`Could not save`))}finally{g(!1)}}}};return(0,F.jsxs)(`form`,{className:`pi-provider-key-form`,onSubmit:e=>{e.preventDefault(),y()},children:[(0,F.jsxs)(`label`,{children:[r(`API Key`,`API key`),(0,F.jsx)(`input`,{type:`password`,autoComplete:`off`,maxLength:16384,value:s,onChange:e=>c(e.target.value),placeholder:t?r(`已配置,输入新值可替换`,`Configured; enter a new key to replace`):r(`输入 API Key`,`Enter API key`)})]}),(0,F.jsxs)(`details`,{className:`pi-provider-advanced`,children:[(0,F.jsx)(`summary`,{children:r(`自定义设置`,`Custom settings`)}),(0,F.jsxs)(`label`,{children:[r(`API 地址(可选)`,`API URL (optional)`),(0,F.jsx)(`input`,{type:`url`,maxLength:2048,value:l,onChange:e=>u(e.target.value),placeholder:r(`使用提供方默认地址`,`Use provider default URL`)})]})]}),(0,F.jsx)(`button`,{type:`submit`,disabled:n||h||p||!s.trim()&&(l.trim()===d||!t),children:h?r(`保存中…`,`Saving…`):t?r(`保存`,`Save`):r(`连接`,`Connect`)}),_&&(0,F.jsx)(`p`,{className:`pi-settings-error`,role:`alert`,children:_})]})}function ak({setupMode:e=!1,onReturnToConversation:t,getProviders:n,getProviderModels:i,updateProviderModel:a,logoutProvider:o,addCustomProvider:s,startLogin:c,getLogin:l,getActiveLogin:u,respondLogin:d,cancelLogin:f,refreshModels:p}){let[m,h]=(0,P.useState)([]),[g,_]=(0,P.useState)(!1),[v,y]=(0,P.useState)(e?`builtin`:null),[b,x]=(0,P.useState)(``),[S,C]=(0,P.useState)(null),[w,T]=(0,P.useState)(null),[E,D]=(0,P.useState)(tk),[O,k]=(0,P.useState)(null),[ee,te]=(0,P.useState)(``),[ne,A]=(0,P.useState)(``),[re,ie]=(0,P.useState)(!1),j=(0,P.useRef)(null);(0,P.useEffect)(()=>{e&&y(e=>e??`builtin`)},[e]),(0,P.useEffect)(()=>{let e=!0;return u().then(t=>{e&&t&&k(e=>e??t)}).catch(()=>{}),()=>{e=!1,j.current?.popup?.close()}},[]);let ae=async()=>{h(await n()),_(!0)},oe=async e=>{let t=j.current,n=e.authorization??(e.event?.type===`auth_url`||e.event?.type===`device_code`?e.event:void 0);if(t?.id===e.id&&n){let e=nk(n.type===`auth_url`?n.url:n.verificationUri);if(e){try{t.popup&&!t.popup.closed?t.popup.location.replace(e):window.open(e,`_blank`,`noopener,noreferrer`)}catch{t.popup?.close()}j.current=null}}t?.id===e.id&&(e.status===`done`||e.status===`error`||e.status===`cancelled`)&&(t.popup?.close(),j.current=null),k(e),e.status===`done`&&(y(null),C(null),await Promise.all([ae(),p()]))};(0,P.useEffect)(()=>{ae().catch(e=>{_(!0),A(e instanceof Error?e.message:r(`无法读取模型提供方`,`Could not load model providers`))})},[]),(0,P.useEffect)(()=>{if(!O||O.status===`done`||O.status===`error`||O.status===`cancelled`)return;let e=!0,t=window.setInterval(()=>{l(O.id).then(async t=>{e&&await oe(t)}).catch(t=>{e&&A(t instanceof Error?t.message:r(`登录状态不可用`,`Login status is unavailable`))})},700);return()=>{e=!1,window.clearInterval(t)}},[O?.id,O?.status]);let M=re||O?.status===`running`||O?.status===`waiting`,se=m.find(e=>e.id===O?.providerId)?.name,ce=m.filter(e=>e.configured),le=m.filter(e=>!e.configured&&e.methods.length>0),ue=le.find(e=>e.id===b)??(e?le.find(e=>e.id===`openai-codex`)??le.find(e=>e.methods.includes(`oauth`)):void 0)??le.find(e=>e.id===`openai`)??le[0],de=async(e,t,n)=>{j.current=t===`oauth`?{id:null,popup:rk()}:null,ie(!0),A(``),te(``);try{let{id:r}=await c(e,t,n);j.current&&(j.current.id=r),await oe(await l(r))}catch(e){j.current?.popup?.close(),j.current=null,A(e instanceof Error?e.message:r(`无法开始登录`,`Could not start sign-in`)),O||u().then(e=>{e&&k(e)}).catch(()=>{})}finally{ie(!1)}},fe=async e=>{if(O){ie(!0),A(``);try{await d(O.id,e),te(``),await oe(await l(O.id))}catch(e){A(e instanceof Error?e.message:r(`提交失败`,`Submission failed`))}finally{ie(!1)}}},pe=async()=>{ie(!0),A(``);try{await s(E);let e=E.id;await ae(),x(e),y(`builtin`),D(tk)}catch(e){A(e instanceof Error?e.message:r(`无法添加自定义提供方`,`Could not add custom provider`))}finally{ie(!1)}},me=async e=>{ie(!0),A(``);try{await o(e),await ae(),T(null),C(null)}catch(e){A(e instanceof Error?e.message:r(`移除认证失败`,`Could not remove credentials`))}finally{ie(!1)}},N=O?.authorization??(O?.event?.type===`auth_url`||O?.event?.type===`device_code`?O.event:void 0),he=O?.status===`waiting`&&O.prompt&&O.prompt.type!==`select`&&(0,F.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),ee.trim()&&fe(ee.trim())},children:[(0,F.jsx)(`label`,{htmlFor:`pi-provider-answer`,children:O.prompt.message}),(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`input`,{id:`pi-provider-answer`,type:O.prompt.type===`secret`?`password`:`text`,autoComplete:`off`,placeholder:O.prompt.placeholder,value:ee,onChange:e=>te(e.target.value)}),(0,F.jsx)(`button`,{type:`submit`,disabled:re||!ee.trim(),children:r(`继续`,`Continue`)})]})]});return(0,F.jsxs)(`div`,{className:`pi-settings-content`,children:[(0,F.jsx)(`h2`,{children:e?r(`先连接一个模型`,`Connect a model to begin`):r(`模型`,`Models`)}),(0,F.jsx)(`p`,{className:`pi-settings-intro`,children:e?r(`当前没有可用模型。选择提供方完成认证,再在会话中选择模型;也可以添加自定义提供方。`,`No models are available yet. Sign in to a provider, then choose a model in the conversation. You can also add a custom provider.`):r(`已接入的提供方显示在这里。添加新的提供方后,即可在会话中选择其模型。`,`Connected providers appear here. Add a provider to use its models in a conversation.`)}),ne&&(0,F.jsx)(`p`,{className:`pi-settings-error`,role:`alert`,children:ne}),O&&(0,F.jsxs)(`section`,{className:`pi-provider-flow`,"aria-label":r(`模型登录`,`Model sign-in`),children:[(0,F.jsxs)(`div`,{className:`pi-provider-flow-head`,children:[(0,F.jsxs)(`strong`,{children:[r(`模型登录`,`Model sign-in`),se?` · ${se}`:``]}),(0,F.jsx)(`button`,{type:`button`,onClick:()=>{j.current?.id===O.id&&(j.current.popup?.close(),j.current=null),O.status===`running`||O.status===`waiting`?f(O.id).finally(()=>k(null)):k(null)},children:O.status===`running`||O.status===`waiting`?r(`取消`,`Cancel`):r(`关闭`,`Close`)})]}),O.status===`done`&&(0,F.jsxs)(`div`,{role:`status`,children:[(0,F.jsx)(`p`,{children:r(`已连接。现在可以在会话中选择该提供方的模型。`,`Connected. You can now select this provider’s models in a conversation.`)}),(0,F.jsx)(`button`,{type:`button`,onClick:t,children:r(`返回会话选择模型`,`Return to conversation and choose a model`)})]}),O.status===`error`&&(0,F.jsx)(`p`,{role:`alert`,children:O.error}),O.status===`running`&&!N&&(0,F.jsx)(`p`,{role:`status`,children:r(`正在等待提供方响应…`,`Waiting for the provider…`)}),O.event?.type===`info`&&(0,F.jsxs)(`p`,{children:[O.event.message,O.event.links?.map(e=>{let t=nk(e.url);return t&&(0,F.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,children:e.label??r(`打开链接`,`Open link`)},t)})]}),O.event?.type===`progress`&&N?.type!==`auth_url`&&(0,F.jsx)(`p`,{children:O.event.message}),N?.type===`auth_url`&&(0,F.jsxs)(`p`,{role:`status`,children:[r(`请在授权页面完成登录;若页面未自动打开,请点击右侧链接。完成后这里会自动更新。`,`Complete sign-in on the authorization page. If it did not open, use the link. This page will update automatically.`),` `,nk(N.url)&&(0,F.jsx)(`a`,{href:nk(N.url),target:`_blank`,rel:`noopener noreferrer`,children:r(`打开授权页面`,`Open authorization page`)})]}),N?.type===`device_code`&&(0,F.jsxs)(`p`,{children:[r(`在`,`On the`),` `,nk(N.verificationUri)&&(0,F.jsx)(`a`,{href:nk(N.verificationUri),target:`_blank`,rel:`noopener noreferrer`,children:r(`验证页面`,`verification page`)}),` `,r(`输入代码`,`enter code`),` `,(0,F.jsx)(`code`,{children:N.userCode})]}),O.status===`waiting`&&O.prompt?.type===`select`&&(0,F.jsxs)(`div`,{className:`pi-provider-options`,children:[(0,F.jsx)(`p`,{children:O.prompt.message}),O.prompt.options.map(e=>(0,F.jsxs)(`button`,{type:`button`,disabled:re,onClick:()=>{fe(e.id)},children:[e.label,e.description&&(0,F.jsx)(`small`,{children:e.description})]},e.id))]}),he&&O.prompt?.type===`manual_code`&&N?.type===`auth_url`?(0,F.jsxs)(`details`,{className:`pi-provider-manual-login`,children:[(0,F.jsx)(`summary`,{children:r(`无法自动完成?手动输入授权码`,`Can't finish automatically? Enter an authorization code`)}),he]}):he]}),(0,F.jsxs)(`section`,{className:`pi-provider-list`,"aria-label":r(`已接入的模型提供方`,`Connected model providers`),children:[ce.map(e=>(0,F.jsxs)(`div`,{className:`pi-provider-card`,children:[(0,F.jsxs)(`div`,{className:`pi-provider-card-head`,children:[(0,F.jsxs)(`span`,{className:`pi-provider-name`,children:[e.name,(0,F.jsx)(`span`,{className:`pi-provider-dot`,role:`img`,"aria-label":r(`已配置认证`,`Authentication configured`)}),(0,F.jsx)(`small`,{children:r(`已配置`,`Configured`)})]}),(0,F.jsx)(`button`,{type:`button`,disabled:M,"aria-label":`${r(`编辑`,`Edit`)} ${e.name}`,"aria-expanded":S===e.id,onClick:()=>{y(null),C(S===e.id?null:e.id)},children:r(`编辑`,`Edit`)})]}),S===e.id&&(0,F.jsxs)(`div`,{className:`pi-provider-editor`,children:[e.methods.includes(`api_key`)&&(0,F.jsx)(ik,{provider:e,configured:!0,busy:!!M,getProviderModels:i,updateProviderModel:a,onConnect:t=>de(e.id,`api_key`,t)},e.id),e.methods.includes(`oauth`)&&(0,F.jsx)(`div`,{className:`pi-provider-methods`,children:(0,F.jsx)(`button`,{type:`button`,disabled:!!M,onClick:()=>{de(e.id,`oauth`)},children:r(`网页登录`,`Browser sign-in`)})}),(0,F.jsx)(ek,{providerId:e.id,getModels:i,updateModel:a}),e.storedCredential&&(0,F.jsx)(`div`,{className:`pi-provider-credential-action`,children:(0,F.jsx)(`button`,{type:`button`,disabled:M,onClick:()=>T(e.id),children:r(`移除认证`,`Remove credentials`)})}),!e.storedCredential&&(0,F.jsx)(`p`,{className:`pi-provider-auth-source`,children:r(`当前认证来自环境变量、模型配置或其他运行时来源,请在对应位置移除。`,`Authentication comes from an environment variable, model configuration, or another runtime source. Remove it at its source.`)}),w===e.id&&(0,F.jsxs)(`div`,{className:`pi-model-confirm`,role:`group`,"aria-label":r(`确认移除认证`,`Confirm credential removal`),children:[(0,F.jsx)(`span`,{children:r(`移除本机保存的认证后,该模型可能无法继续使用。`,`Removing stored credentials may make this provider unavailable.`)}),(0,F.jsx)(`button`,{type:`button`,disabled:re,onClick:()=>{me(e.id)},children:r(`确认移除`,`Remove`)}),(0,F.jsx)(`button`,{type:`button`,disabled:re,onClick:()=>T(null),children:r(`取消`,`Cancel`)})]})]})]},e.id)),g&&ce.length===0&&(0,F.jsx)(`p`,{className:`pi-provider-empty`,children:r(`尚未接入提供方`,`No providers connected yet`)}),!g&&(0,F.jsx)(`p`,{role:`status`,children:r(`正在读取模型提供方…`,`Loading model providers…`)})]}),v===`builtin`&&(0,F.jsxs)(`section`,{className:`pi-provider-add-card`,"aria-label":r(`添加提供方`,`Add provider`),children:[(0,F.jsxs)(`div`,{className:`pi-provider-flow-head`,children:[(0,F.jsx)(`strong`,{children:r(`添加提供方`,`Add provider`)}),(0,F.jsx)(`button`,{type:`button`,onClick:()=>y(null),children:r(`关闭`,`Close`)})]}),ue?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`label`,{htmlFor:`pi-provider-select`,children:r(`提供方`,`Provider`)}),(0,F.jsx)(`select`,{id:`pi-provider-select`,value:ue.id,onChange:e=>x(e.target.value),children:le.map(e=>(0,F.jsx)(`option`,{value:e.id,children:e.name},e.id))}),ue.methods.includes(`api_key`)&&(0,F.jsx)(ik,{provider:ue,configured:!1,busy:!!M,getProviderModels:i,updateProviderModel:a,onConnect:e=>de(ue.id,`api_key`,e)},ue.id),ue.methods.includes(`oauth`)&&(0,F.jsx)(`div`,{className:`pi-provider-methods`,children:(0,F.jsx)(`button`,{type:`button`,disabled:!!M,onClick:()=>{de(ue.id,`oauth`)},children:r(`网页登录`,`Browser sign-in`)})}),(0,F.jsx)(`p`,{children:r(`认证完成后,可在提供方的“编辑”中调整模型目录。`,`After sign-in, open the provider’s Edit panel to adjust its model catalog.`)})]}):(0,F.jsx)(`p`,{children:r(`没有可添加的提供方。`,`No providers can be added.`)})]}),v===`custom`&&(0,F.jsxs)(`section`,{className:`pi-provider-add-card`,"aria-label":r(`添加自定义提供方`,`Add custom provider`),children:[(0,F.jsxs)(`div`,{className:`pi-provider-flow-head`,children:[(0,F.jsx)(`strong`,{children:r(`添加自定义提供方`,`Add custom provider`)}),(0,F.jsx)(`button`,{type:`button`,onClick:()=>y(null),children:r(`关闭`,`Close`)})]}),(0,F.jsx)(`p`,{children:r(`适用于兼容 Pi 已支持协议的模型服务。保存后再添加 API Key;密钥不会写入 models.json。`,`For model services compatible with Pi’s supported protocols. Add an API key after saving; it will not be written to models.json.`)}),(0,F.jsxs)(`form`,{className:`pi-provider-custom-form`,onSubmit:e=>{e.preventDefault(),pe()},children:[(0,F.jsxs)(`label`,{children:[r(`名称`,`Name`),(0,F.jsx)(`input`,{required:!0,maxLength:100,value:E.name,onChange:e=>D({...E,name:e.target.value}),placeholder:r(`我的模型服务`,`My model service`)})]}),(0,F.jsxs)(`label`,{children:[r(`提供方 ID`,`Provider ID`),(0,F.jsx)(`input`,{required:!0,maxLength:64,value:E.id,onChange:e=>D({...E,id:e.target.value}),placeholder:`my-provider`})]}),(0,F.jsxs)(`label`,{children:[r(`接口地址`,`API URL`),(0,F.jsx)(`input`,{required:!0,type:`url`,maxLength:2048,value:E.baseUrl,onChange:e=>D({...E,baseUrl:e.target.value}),placeholder:`https://api.example.com/v1`})]}),(0,F.jsxs)(`label`,{children:[r(`接口协议`,`API protocol`),(0,F.jsxs)(`select`,{value:E.api,onChange:e=>D({...E,api:e.target.value}),children:[(0,F.jsx)(`option`,{value:`openai-completions`,children:`OpenAI Chat Completions`}),(0,F.jsx)(`option`,{value:`openai-responses`,children:`OpenAI Responses`}),(0,F.jsx)(`option`,{value:`anthropic-messages`,children:`Anthropic Messages`})]})]}),(0,F.jsxs)(`label`,{children:[r(`模型 ID`,`Model ID`),(0,F.jsx)(`input`,{required:!0,maxLength:200,value:E.modelId,onChange:e=>D({...E,modelId:e.target.value}),placeholder:`model-name`})]}),(0,F.jsx)(`button`,{type:`submit`,disabled:re,children:r(`保存并继续`,`Save and continue`)})]})]}),!v&&(0,F.jsxs)(`div`,{className:`pi-provider-add-actions`,children:[(0,F.jsx)(`button`,{type:`button`,disabled:!g||le.length===0||M,onClick:()=>{C(null),y(`builtin`),x(``)},children:r(`+ 添加提供方`,`+ Add provider`)}),(0,F.jsx)(`button`,{type:`button`,disabled:M,onClick:()=>{C(null),y(`custom`)},children:r(`+ 添加自定义提供方`,`+ Add custom provider`)})]})]})}var ok=`pi-web-theme`,sk=new Set,ck=window.matchMedia(`(prefers-color-scheme: dark)`),lk=uk();function uk(){try{let e=localStorage.getItem(ok);if(e===`light`||e===`dark`||e===`system`)return e}catch{}return`system`}function dk(){document.body.toggleAttribute(`data-ds-dark-theme`,lk===`dark`||lk===`system`&&ck.matches)}function fk(){dk(),ck.addEventListener(`change`,dk),window.addEventListener(`storage`,e=>{e.key===ok&&(lk=uk(),dk(),sk.forEach(e=>e()))})}function pk(e){lk=e;try{localStorage.setItem(ok,e)}catch{}dk(),sk.forEach(e=>e())}function mk(){return(0,P.useSyncExternalStore)(e=>(sk.add(e),()=>{sk.delete(e)}),()=>lk)}var hk={group:`_group_8jvbt_4`,title:`_title_8jvbt_12`,cubeRow:`_cubeRow_8jvbt_19`,themeCube:`_themeCube_8jvbt_29`,selected:`_selected_8jvbt_48`};function gk(){let e=mk(),t=l(),r=[{id:`light`,label:t===`zh`?`浅色`:`Light`,Icon:Ct},{id:`dark`,label:t===`zh`?`深色`:`Dark`,Icon:wt},{id:`system`,label:t===`zh`?`跟随系统`:`System`,Icon:Tt}];return(0,F.jsxs)(`div`,{className:hk.group,children:[(0,F.jsx)(`div`,{className:hk.title,children:t===`zh`?`外观`:`Appearance`}),(0,F.jsx)(`div`,{className:hk.cubeRow,children:r.map(({id:t,label:r,Icon:i})=>(0,F.jsxs)(`button`,{type:`button`,className:n(hk.themeCube,e===t&&hk.selected),"aria-pressed":e===t,onClick:()=>pk(t),children:[(0,F.jsx)(i,{}),r]},t))})]})}var _k={selectorWrap:`_selectorWrap_5eqgx_1`,selector:`_selector_5eqgx_1`,value:`_value_5eqgx_23`,option:`_option_5eqgx_24`,chevron:`_chevron_5eqgx_25`,menu:`_menu_5eqgx_27`};function vk({label:e,menuLabel:t,value:n,options:r,disabled:i,onChange:a}){let[o,s]=(0,P.useState)(!1),c=(0,P.useId)(),l=(0,P.useRef)(null),u=(0,P.useRef)(null),d=(0,P.useRef)(null);return(0,P.useEffect)(()=>{i&&s(!1)},[i]),(0,P.useEffect)(()=>{if(!o)return;d.current?.focus();let e=e=>{l.current?.contains(e.target)||s(!1)},t=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopImmediatePropagation(),s(!1),u.current?.focus())};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[o]),(0,F.jsxs)(`div`,{className:_k.selectorWrap,ref:l,onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||s(!1)},children:[(0,F.jsxs)(`button`,{ref:u,type:`button`,className:_k.selector,"aria-label":e,"aria-haspopup":`menu`,"aria-expanded":o,"aria-controls":o?c:void 0,disabled:i,onClick:()=>s(e=>!e),children:[(0,F.jsx)(`span`,{className:_k.value,children:r.find(e=>e.id===n)?.label}),(0,F.jsx)(`svg`,{className:_k.chevron,width:`14`,height:`14`,viewBox:`0 0 14 14`,fill:`none`,"aria-hidden":`true`,children:(0,F.jsx)(`path`,{d:`m3.5 5.25 3.5 3.5 3.5-3.5`,stroke:`currentColor`,strokeWidth:`1.4`,strokeLinecap:`round`,strokeLinejoin:`round`})})]}),o&&(0,F.jsx)(`div`,{id:c,className:_k.menu,role:`menu`,"aria-label":t,onKeyDown:e=>{if(![`ArrowDown`,`ArrowUp`,`Home`,`End`].includes(e.key))return;e.preventDefault();let t=Array.from(e.currentTarget.querySelectorAll(`[role="menuitemradio"]`)),n=t.indexOf(document.activeElement);t[e.key===`Home`?0:e.key===`End`?t.length-1:(n+(e.key===`ArrowDown`?1:t.length-1))%t.length]?.focus()},children:r.map(e=>(0,F.jsxs)(`button`,{ref:e.id===n?d:void 0,type:`button`,role:`menuitemradio`,"aria-checked":e.id===n,className:_k.option,onClick:()=>{s(!1),u.current?.focus(),e.id!==n&&a(e.id)},children:[(0,F.jsx)(`span`,{children:e.label}),e.id===n&&(0,F.jsx)(`svg`,{className:_k.chevron,width:`16`,height:`16`,viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,children:(0,F.jsx)(`path`,{d:`m3 8 3.2 3.2L13 4.5`,stroke:`currentColor`,strokeWidth:`1.7`,strokeLinecap:`round`,strokeLinejoin:`round`})})]},e.id))})]})}var yk={row:`_row_1rrpk_1`,title:`_title_1rrpk_9`},bk=[{id:`zh`,label:`中文`},{id:`en`,label:`English`}];function xk(){let e=l(),t=e===`zh`?`语言`:`Language`;return(0,F.jsxs)(`div`,{className:yk.row,children:[(0,F.jsx)(`div`,{className:yk.title,children:t}),(0,F.jsx)(vk,{label:t,menuLabel:e===`zh`?`选择语言`:`Choose language`,value:e,options:bk,onChange:i})]})}function Sk(e,t,n){return e instanceof m&&e.status===404?t===`zh`?`后台服务仍在运行旧版。请重启 pi-webapp 后重新打开页面,再检查更新。`:`The background service is still running an older version. Restart pi-webapp, reopen this page, then check again.`:e instanceof Error&&e.message?e.message:n===`check`?t===`zh`?`检查更新失败`:`Could not check for updates`:t===`zh`?`升级失败`:`Update failed`}function Ck({getUpdate:e,getRunningVersion:t,setUpdateChannel:n,cancelUpdate:r,update:i}){let a=l(),[o,s]=(0,P.useState)(null),[c,u]=(0,P.useState)(!0),[d,p]=(0,P.useState)(!1),[m,h]=(0,P.useState)(!1),[g,_]=(0,P.useState)(null),[v,y]=(0,P.useState)(!1),[b,x]=(0,P.useState)(``),S=(0,P.useRef)(!1),C=(0,P.useRef)(!1),w=(0,P.useRef)(0),T=(0,P.useRef)(!0);(0,P.useEffect)(()=>(T.current=!0,()=>{T.current=!1}),[]);let E=async()=>{let t=++w.current;u(!0),x(``);try{let n=await e();T.current&&t===w.current&&s(n)}catch(e){T.current&&t===w.current&&(s(null),x(Sk(e,a,`check`)))}finally{T.current&&t===w.current&&u(!1)}};return(0,P.useEffect)(()=>{E();let e=()=>{E()};return window.addEventListener(`pi-update-channel`,e),()=>{window.removeEventListener(`pi-update-channel`,e)}},[]),(0,P.useEffect)(()=>{if(!g)return;let e=!1,n=new AbortController,r,i=setTimeout(()=>{e=!0,n.abort(),clearTimeout(r),_(null),y(!0),x(f(a,`新版未能及时就绪,后台可能已回退到旧版。请刷新页面检查当前版本;若无法连接,请重新打开应用。`,`The new version was not ready in time; the backend may have rolled back. Refresh to check the running version, or reopen the app if disconnected.`)),_e(Error(`Updated service did not become ready within 60 seconds`),{stage:`update_restart`,code:`update_restart_timeout`,route:`/api/update/version`,timeoutMs:6e4})},6e4),o=async()=>{try{let r=await t(n.signal);if(e)return;if(r.current===g){clearTimeout(i),location.reload();return}}catch{}e||(r=setTimeout(()=>{o()},1200))};return r=setTimeout(()=>{o()},1200),()=>{e=!0,n.abort(),clearTimeout(r),clearTimeout(i)}},[g]),{status:o,checking:c,installing:d,cancelling:m,targetVersion:g,restartTimedOut:v,error:b,check:E,install:async()=>{if(S.current||c||!o?.available||!o.canRestart||g||v||o.downgrade&&!window.confirm(f(a,`将从 ${o.current} 切换至稳定版 ${o.latest}。部分新功能可能不可用;请先备份重要数据。是否继续?`,`Switch from ${o.current} to stable ${o.latest}? Some new features may be unavailable. Back up important data before continuing.`)))return;S.current=!0,p(!0),x(``);let t=o.channel&&o.latest?{channel:o.channel,version:o.latest,...o.downgrade?{allowDowngrade:!0}:{}}:void 0;try{let e;try{e=await i(t)}catch(n){if(n?.reason!==`update_confirm_required`)throw n;if(!window.confirm(f(a,`${n.message}。\n\n仍然升级?`,`${n.message}.\n\nUpdate anyway?`)))return;e=await i({...t,force:!0})}T.current&&_(e.version)}catch(t){T.current&&x(Sk(t,a,`install`));try{let t=await e();T.current&&s(t)}catch{}}finally{S.current=!1,T.current&&p(!1)}},changeChannel:async e=>{if(!(!n||c||d||g)){++w.current,u(!0),x(``);try{await n(e),window.dispatchEvent(new Event(`pi-update-channel`))}catch(e){T.current&&(u(!1),x(Sk(e,a,`check`)))}}},cancel:async()=>{if(!(!r||C.current||g)){C.current=!0,h(!0),x(``);try{await r(),y(!1),await E()}catch(e){T.current&&x(Sk(e,a,`install`))}finally{C.current=!1,T.current&&h(!1)}}}}}var wk=(0,P.createContext)(null);function Tk({actions:e,children:t}){let n=Ck(e);return(0,F.jsx)(wk.Provider,{value:n,children:t})}function Ek(){return(0,P.useContext)(wk)}function Dk(e){let t=/(?:^| )PiDesktop\/(\d+\.\d+\.\d+(?:-[\w.-]+)?) PiDesktopBuild\/(\d+)(?: |$)/.exec(e);return!t||t[1].length>80||!Number.isSafeInteger(Number(t[2]))?null:{version:t[1],build:Number(t[2]),handoff:Number(t[2])>=14}}var Ok={group:`_group_14gt8_1`,row:`_row_14gt8_8`,details:`_details_14gt8_15`,preference:`_preference_14gt8_17`,title:`_title_14gt8_25`,summary:`_summary_14gt8_31`,note:`_note_14gt8_31`,error:`_error_14gt8_31`,diagnostics:`_diagnostics_14gt8_41`,actions:`_actions_14gt8_51`};function kk(e){let t=Ek();return t?(0,F.jsx)(jk,{...e,controller:t}):(0,F.jsx)(Ak,{...e})}function Ak(e){let t=Ck(e);return(0,F.jsx)(jk,{...e,controller:t})}function jk(e){let t=l(),n=(e,n)=>f(t,e,n),{status:r,checking:i,installing:a,cancelling:o,targetVersion:s,restartTimedOut:c,error:u,check:d,install:p,changeChannel:m,cancel:h}=e.controller,g=Dk(navigator.userAgent),_=!(!r?.latest||r.available||i),v=r?(0,F.jsxs)(F.Fragment,{children:[n(`当前版本`,`Current version`),` `,r.current,r.available&&r.latest?` → ${r.latest}`:_&&(0,F.jsxs)(F.Fragment,{children:[` · `,(0,F.jsx)(`span`,{role:`status`,children:n(`已是最新版本`,`Up to date`)})]})]}):i?n(`正在读取版本…`,`Reading version…`):n(`暂时无法读取版本`,`Version unavailable`),y=!!(g&&r?.desktopShell&&String(g.build)!==r.desktopShell.build)||!!(r?.launcherHandoff?.required||r?.requiresDesktopUpgrade||r?.launcher&&!r.launcher.releaseChannels),b=!!(g||r?.launcher||r?.desktopShell);return(0,F.jsxs)(`section`,{className:Ok.group,"aria-label":n(`应用更新`,`App updates`),children:[r?.channel&&e.setUpdateChannel&&(0,F.jsxs)(`div`,{className:Ok.preference,children:[(0,F.jsx)(`div`,{className:Ok.title,children:n(`更新偏好`,`Update preference`)}),(0,F.jsx)(vk,{label:n(`更新偏好`,`Update preference`),menuLabel:n(`选择更新偏好`,`Choose update preference`),value:r.channel,disabled:i||a||!!s||c,onChange:e=>{m(e)},options:[{id:`stable`,label:n(`稳定版(推荐)`,`Stable (recommended)`)},{id:`alpha`,label:n(`体验版(包含 alpha)`,`Preview (including alpha)`)}]})]}),r?.channel===`alpha`&&(0,F.jsx)(`p`,{className:Ok.note,children:n(`体验版包含尚在验证的新功能,可能不稳定。`,`Preview releases include features still under testing and may be unstable.`)}),(0,F.jsxs)(`div`,{className:Ok.row,children:[(0,F.jsxs)(`div`,{className:Ok.details,children:[(0,F.jsx)(`div`,{className:Ok.title,children:n(`应用更新`,`App updates`)}),(0,F.jsx)(`p`,{className:Ok.summary,children:v})]}),(0,F.jsxs)(`div`,{className:Ok.actions,children:[r?.available&&r.canRestart&&!s&&!c&&(0,F.jsx)(EO,{variant:`primary`,disabled:a||i,onClick:()=>{p()},children:a?n(`正在安装…`,`Installing…`):r.downgrade?n(`切换到稳定版并重启`,`Switch to stable and restart`):n(`升级并重启`,`Update and restart`)}),(r?.recovery?.canCancel||a)&&e.cancelUpdate&&!s&&(0,F.jsx)(EO,{variant:`outline`,disabled:o,onClick:()=>{h()},children:o?n(`正在取消…`,`Cancelling…`):a?n(`取消下载`,`Cancel download`):n(`取消未完成的升级`,`Cancel unfinished update`)}),(0,F.jsx)(EO,{variant:`outline`,disabled:i||a||!!s,onClick:()=>{d()},children:i?n(`检查中…`,`Checking…`):n(`检查更新`,`Check for updates`)})]})]}),r?.launcherHandoff?.required&&(0,F.jsxs)(`div`,{className:Ok.note,children:[(0,F.jsx)(`p`,{children:n(`安装新版桌面不会自动接管仍在运行的共享后台。需要先安全交接启动器,再使用体验版在线升级。交接会等待聊天空闲、终端关闭和真实图稿保存确认,并保留原本地地址。`,`Installing a desktop update does not take over a running shared backend. Safely hand off the launcher before preview updates. Handoff requires idle chats, closed terminals and real drawing save confirmations, and preserves the local address.`)}),g?.handoff?(0,F.jsx)(`a`,{href:`pi-desktop://launcher-handoff`,target:`_blank`,rel:`noreferrer`,children:n(`安全切换到当前桌面启动器…`,`Safely switch to this desktop launcher…`)}):(0,F.jsxs)(`p`,{children:[n(`安全交接入口从桌面 build 14 开始提供。build 12 已支持体验版,但缺少旧共享后台交接功能;无需重复安装 build 12。`,`The safe handoff action is available from desktop build 14. Build 12 supports preview releases but lacks shared-backend handoff; reinstalling build 12 will not help.`),` `,(0,F.jsx)(`a`,{href:`https://github.com/chengzhiyi/pi-webapp/releases`,target:`_blank`,rel:`noreferrer`,children:n(`下载支持安全交接的桌面版本`,`Get a desktop release with safe handoff`)})]}),!r.launcherHandoff.supported&&(0,F.jsx)(`p`,{children:n(`当前后台还缺少安全交接协议:请先选择稳定版并升级业务包,再从桌面菜单重试交接。`,`This backend lacks the safe handoff protocol: first update its business package on Stable, then retry from the desktop menu.`)})]}),r?.available&&!!r.pluginWarnings?.length&&(0,F.jsxs)(`div`,{className:Ok.note,children:[(0,F.jsx)(`p`,{children:n(`以下插件在新版本中暂时不可用(不影响升级,数据保留):`,`These plugins will be unavailable on the new version (the update is not blocked; their data is kept):`)}),(0,F.jsx)(`ul`,{children:r.pluginWarnings.map(e=>(0,F.jsxs)(`li`,{children:[e.pluginId,`: `,e.message]},e.pluginId))})]}),r?.lastFailure&&!a&&!s&&(0,F.jsxs)(`p`,{className:Ok.note,children:[n(`上次升级到 ${r.lastFailure.version} 未完成,已保留当前版本:`,`The last update to ${r.lastFailure.version} did not complete; the current version was kept: `),r.lastFailure.message]}),r?.reason&&(0,F.jsx)(`p`,{className:Ok.note,children:r.reason}),r?.requiresDesktopUpgrade&&(0,F.jsxs)(`p`,{className:Ok.note,children:[(0,F.jsx)(`a`,{href:`https://github.com/chengzhiyi/pi-webapp/releases`,target:`_blank`,rel:`noreferrer`,children:n(`下载新版桌面应用`,`Download desktop update`)}),n(`。安装支持更新通道的桌面版本后,可在此选择体验版并在线升级。`,`. Install a desktop release with update-channel support, then return here to select preview and update online.`)]}),s&&(0,F.jsx)(`p`,{className:Ok.note,role:`status`,children:n(`正在重启并等待新版连接…`,`Restarting and waiting for the new version…`)}),u&&(0,F.jsx)(`p`,{className:Ok.error,role:`alert`,children:u}),u?.includes(`Missing view flush acknowledgement`)&&(0,F.jsx)(`p`,{className:Ok.note,children:n(`插件视图尚未确认保存。请保存并关闭绘图或编辑器;若视图已失联,请先在插件恢复记录中处理未确认的编辑,再重试升级。`,`A plugin view has not confirmed its save. Save and close drawings or editors; if a view disconnected, review its unconfirmed edits in plugin recovery before retrying.`)}),b&&(0,F.jsxs)(`details`,{className:Ok.diagnostics,open:y,children:[(0,F.jsx)(`summary`,{children:n(`版本详情`,`Version details`)}),g&&(0,F.jsxs)(`p`,{className:Ok.summary,children:[n(`当前桌面窗口`,`Current desktop window`),` `,g.version,` · build `,g.build]}),r?.launcher&&(0,F.jsxs)(`p`,{className:Ok.summary,children:[n(`后台启动器`,`Backend launcher`),` `,r.launcher.version,` · `,n(`体验版持久化`,`Preview persistence`),` `,r.launcher.releaseChannels?n(`支持`,`supported`):n(`不支持`,`unsupported`)]}),r?.desktopShell&&(0,F.jsxs)(`p`,{className:Ok.summary,children:[n(`后台启动时的桌面外壳`,`Desktop shell at backend startup`),` `,r.desktopShell.version,` · build `,r.desktopShell.build]}),r?.desktopShell&&(0,F.jsx)(`p`,{className:Ok.note,children:n(`共享后台可能由旧版桌面启动。当前窗口的桌面版本请查看菜单「pi → 关于 pi」。业务包升级不会替换桌面应用。`,`A shared backend may have been started by an older desktop. For this window’s desktop version, see pi → About pi. Updating the business package does not replace the desktop app.`)})]})]})}var Mk=`https://pi.emath.top`,Nk=`https://github.com/chengzhiyi/pi-webapp/issues`;function Pk(e,t){let n={home:``,quickStart:`getting-started`,troubleshooting:`troubleshooting`}[e];return`${Mk}/${String(t).toLowerCase().startsWith(`zh`)?`zh/`:``}${n}`}function Fk(e){let t=(t,n)=>f(e,t,n);return[{id:`docs`,label:t(`使用文档`,`Documentation`),href:Pk(`home`,e)},{id:`quick-start`,label:t(`快速开始`,`Quick start`),href:Pk(`quickStart`,e)},{id:`troubleshooting`,label:t(`故障排查`,`Troubleshooting`),href:Pk(`troubleshooting`,e)},{id:`issues`,label:t(`在 GitHub 上反馈问题`,`Report an issue on GitHub`),href:Nk}]}var Ik={row:`_row_wp8ea_1`,title:`_title_wp8ea_9`,summary:`_summary_wp8ea_15`,links:`_links_wp8ea_22`};function Lk(){let e=l(),t=(t,n)=>f(e,t,n);return(0,F.jsxs)(`section`,{className:Ik.row,"aria-label":t(`帮助与文档`,`Help & documentation`),children:[(0,F.jsx)(`div`,{className:Ik.title,children:t(`帮助与文档`,`Help & documentation`)}),(0,F.jsx)(`p`,{className:Ik.summary,children:t(`查看使用指南、快速开始和常见问题的解决方法。`,`Read the guides, get started quickly, and find fixes for common problems.`)}),(0,F.jsx)(`ul`,{className:Ik.links,children:Fk(e).map(e=>(0,F.jsx)(`li`,{children:(0,F.jsx)(`a`,{href:e.href,target:`_blank`,rel:`noreferrer`,children:e.label})},e.id))})]})}var Rk={triggerRow:`_triggerRow_f00qz_1`,railRow:`_railRow_f00qz_10`,trigger:`_trigger_f00qz_1`,rail:`_rail_f00qz_10`,triggerLabel:`_triggerLabel_f00qz_54`,overlay:`_overlay_f00qz_61`,mask:`_mask_f00qz_70`,panel:`_panel_f00qz_83`,nav:`_nav_f00qz_105`,navTitle:`_navTitle_f00qz_116`,navList:`_navList_f00qz_125`,navCell:`_navCell_f00qz_133`,active:`_active_f00qz_156`,navIcon:`_navIcon_f00qz_160`,navLabel:`_navLabel_f00qz_164`,content:`_content_f00qz_173`,header:`_header_f00qz_181`,actions:`_actions_f00qz_192`,close:`_close_f00qz_202`,options:`_options_f00qz_82`,hiddenLabel:`_hiddenLabel_f00qz_229`};function zk(e){return e===`general`?(0,F.jsx)(rt,{className:Rk.navIcon,size:16}):e===`models`?(0,F.jsx)(Et,{className:Rk.navIcon,size:16}):e===`packages`?(0,F.jsx)(At,{className:Rk.navIcon,size:16}):e===`plugins`||e===`extensions`?(0,F.jsx)(yt,{className:Rk.navIcon,size:16}):(0,F.jsx)(Ot,{className:Rk.navIcon,size:16})}function Bk({title:e,sections:t,activeId:n,onSelect:r,onClose:i,children:a}){let o=l(),s=(0,P.useId)(),c=(0,P.useRef)(null);return(0,P.useEffect)(()=>{c.current?.focus();let e=e=>{e.key===`Escape`&&!e.defaultPrevented&&!(e.target instanceof Element&&e.target.closest(`[role="menu"]`))&&i()};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[i]),(0,F.jsxs)(`div`,{className:Rk.overlay,role:`presentation`,children:[(0,F.jsx)(`div`,{className:Rk.mask,"aria-hidden":`true`,onClick:i}),(0,F.jsxs)(`div`,{className:Rk.panel,role:`dialog`,"aria-modal":`true`,"aria-labelledby":s,children:[(0,F.jsxs)(`nav`,{className:Rk.nav,"aria-label":o===`zh`?`Pi 设置分类`:`Pi settings sections`,children:[(0,F.jsx)(`div`,{className:Rk.navTitle,id:s,children:e}),(0,F.jsx)(`div`,{className:Rk.navList,children:t.map(e=>(0,F.jsxs)(`button`,{type:`button`,className:`${Rk.navCell} ${n===e.id?Rk.active:``}`,"aria-current":n===e.id?`true`:void 0,onClick:()=>r(e.id),children:[zk(e.id),(0,F.jsx)(`span`,{className:Rk.navLabel,children:e.label})]},e.id))})]}),(0,F.jsxs)(`div`,{className:Rk.content,children:[(0,F.jsxs)(`header`,{className:Rk.header,children:[(0,F.jsx)(`div`,{className:Rk.actions}),(0,F.jsx)(`button`,{ref:c,className:Rk.close,type:`button`,onClick:i,"aria-label":o===`zh`?`关闭 Pi 设置`:`Close Pi settings`,children:(0,F.jsx)(ut,{size:14})})]}),(0,F.jsx)(`div`,{className:Rk.options,children:a})]})]})]})}function Vk(e){return/^(?:npm:|git:|https?:\/\/|ssh:\/\/|git@)/i.test(e.trim())}function Hk(e){let t=l(),n=(e,n)=>f(t,e,n),r=[{kind:`packages`,title:n(`包与扩展`,`Packages & extensions`),hint:n(`包可以包含扩展和技能;本地扩展也可以单独加载。`,`Packages can contain extensions and skills; local extensions can also be loaded separately.`),placeholder:n(`npm 包名、Git 地址或本地目录`,`npm package, Git URL, or local directory`)},{kind:`skills`,title:n(`技能`,`Skills`),hint:n(`Pi 已发现和加载的技能。`,`Skills discovered and loaded by Pi.`),placeholder:n(`SKILL.md 文件或目录路径`,`SKILL.md file or directory path`)}],i=[{id:`general`,label:n(`通用设置`,`General`)},{id:`models`,label:n(`模型`,`Models`)},...r.map(({kind:e,title:t})=>({id:e,label:e===`packages`?n(`包与扩展`,`Packages`):t}))],{onBack:a,getConfig:o,updateConfig:s}=e,[c,u]=(0,P.useState)(null),[d,p]=(0,P.useState)({packages:``,extensions:``,skills:``}),[m,h]=(0,P.useState)(e.setupMode?`models`:`general`),[g,_]=(0,P.useState)(!1),[v,y]=(0,P.useState)(!0),[b,x]=(0,P.useState)(``);(0,P.useEffect)(()=>{e.setupMode&&h(`models`)},[e.setupMode]),(0,P.useEffect)(()=>{let e=!0;return o().then(t=>{e&&u(t)}).catch(t=>{e&&x(t instanceof Error?t.message:n(`无法读取 Pi 设置`,`Could not load Pi settings`))}).finally(()=>{e&&y(!1)}),()=>{e=!1}},[]);let S=async()=>{y(!0),x(``);try{u(await o())}catch(e){x(e instanceof Error?e.message:n(`无法读取 Pi 设置`,`Could not load Pi settings`))}finally{y(!1)}},C=async(e,t,r)=>{_(!0),x(``);try{u(await s(e,`global`,t,r)),t===`add`&&p(t=>({...t,[e]:``}))}catch(e){x(e instanceof Error?e.message:n(`保存失败`,`Save failed`))}finally{_(!1)}},w=r.find(({kind:e})=>e===m),T=w?c?.global[w.kind]??[]:[],E=w?c?.installed?.[w.kind]??[]:[],D=w?d[w.kind].trim():``,O=w?.kind!==`packages`&&Vk(D),k=new Set(c?.installed.packages.map(e=>e.source)??[]),ee=c?.installed.extensions.filter(e=>!k.has(e.source))??[],te=c?.global.packages.filter(e=>!k.has(e))??[],ne=d.extensions.trim(),A=Vk(ne),re=e=>{p(t=>({...t,packages:e})),h(`packages`),x(``)};return(0,F.jsxs)(Bk,{title:n(`Pi 设置`,`Pi Settings`),sections:i,activeId:m,onSelect:e=>{h(e),x(``)},onClose:a,children:[m===`general`&&(0,F.jsxs)(`div`,{className:`pi-settings-content`,children:[(0,F.jsx)(`h2`,{children:n(`通用设置`,`General`)}),(0,F.jsx)(`p`,{className:`pi-settings-intro`,children:n(`调整网页的显示方式。`,`Choose how the web interface appears.`)}),(0,F.jsxs)(`div`,{className:`pi-settings-general`,children:[(0,F.jsx)(xk,{}),(0,F.jsx)(gk,{}),(0,F.jsx)(kk,{getUpdate:e.getUpdate,getRunningVersion:e.getRunningVersion,setUpdateChannel:e.setUpdateChannel,cancelUpdate:e.cancelUpdate,update:e.update}),(0,F.jsx)(Lk,{})]})]}),m===`models`&&(0,F.jsx)(ak,{setupMode:e.setupMode,onReturnToConversation:a,getProviders:e.getProviders,getProviderModels:e.getProviderModels,updateProviderModel:e.updateProviderModel,logoutProvider:e.logoutProvider,addCustomProvider:e.addCustomProvider,startLogin:e.startProviderLogin,getLogin:e.getProviderLogin,getActiveLogin:e.getActiveProviderLogin,respondLogin:e.respondProviderLogin,cancelLogin:e.cancelProviderLogin,refreshModels:e.refreshModels}),w&&(0,F.jsxs)(`div`,{className:`pi-settings-content`,children:[(0,F.jsx)(`h2`,{children:w.title}),(0,F.jsxs)(`p`,{className:`pi-settings-intro`,children:[w.hint,` `,n(`添加或移除后会重新加载 Pi 资源。`,`Pi resources reload after you add or remove one.`)]}),b&&(0,F.jsx)(`p`,{className:`pi-settings-error`,role:`alert`,children:b}),c?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`section`,{className:`pi-settings-section`,"aria-label":`${n(`已发现`,`Discovered `)}${w.title}`,children:[(0,F.jsxs)(`h3`,{children:[w.kind===`packages`?n(`已安装的包`,`Installed packages`):n(`已发现的技能`,`Discovered skills`),` `,(0,F.jsx)(`span`,{children:E.length})]}),(0,F.jsx)(`ul`,{children:E.length?E.map(e=>{let t=w.kind===`packages`?c.installed.extensions.filter(t=>t.source===e.source):[];return(0,F.jsxs)(`li`,{className:`pi-resource-item`,children:[(0,F.jsxs)(`div`,{className:`pi-resource-main`,children:[(0,F.jsx)(`strong`,{title:e.name,children:e.name}),(0,F.jsx)(`small`,{title:e.path||e.source,children:e.path||e.source}),t.length>0&&(0,F.jsxs)(`div`,{className:`pi-package-contents`,children:[(0,F.jsx)(`span`,{children:n(`包含扩展`,`Includes extensions`)}),t.map(e=>(0,F.jsx)(`span`,{title:e.path,children:e.name},e.path))]})]}),(0,F.jsxs)(`div`,{className:`pi-resource-actions`,children:[(0,F.jsxs)(`span`,{className:`pi-resource-meta`,children:[e.enabled?n(`已启用`,`Enabled`):n(`已停用`,`Disabled`),` · `,e.scope===`project`?n(`项目`,`Project`):e.scope===`user`?n(`用户`,`User`):n(`临时`,`Temporary`)]}),w.kind===`packages`&&c.global.packages.includes(e.source)&&(0,F.jsx)(`button`,{type:`button`,disabled:g,onClick:()=>{C(`packages`,`remove`,e.source)},children:n(`移除`,`Remove`)})]})]},`${e.path}:${e.source}`)}):(0,F.jsxs)(`li`,{className:`pi-settings-empty`,children:[n(`未发现`,`No `),w.title]})})]}),w.kind===`packages`&&(0,F.jsxs)(`section`,{className:`pi-settings-section`,"aria-label":n(`独立扩展`,`Standalone extensions`),children:[(0,F.jsxs)(`h3`,{children:[n(`独立扩展`,`Standalone extensions`),` `,(0,F.jsx)(`span`,{children:ee.length})]}),(0,F.jsx)(`ul`,{children:ee.length?ee.map(e=>(0,F.jsxs)(`li`,{className:`pi-resource-item`,children:[(0,F.jsxs)(`div`,{className:`pi-resource-main`,children:[(0,F.jsx)(`strong`,{title:e.name,children:e.name}),(0,F.jsx)(`small`,{title:e.path,children:e.path})]}),(0,F.jsxs)(`span`,{className:`pi-resource-meta`,children:[e.enabled?n(`已启用`,`Enabled`):n(`已停用`,`Disabled`),` · `,e.scope===`project`?n(`项目`,`Project`):e.scope===`user`?n(`用户`,`User`):n(`临时`,`Temporary`)]})]},e.path)):(0,F.jsx)(`li`,{className:`pi-settings-empty`,children:n(`未发现独立扩展`,`No standalone extensions found`)})})]}),(0,F.jsxs)(`section`,{className:`pi-settings-section`,"aria-label":`${n(`手动配置`,`Configure `)}${w.title}`,children:[(0,F.jsx)(`h3`,{children:w.kind===`packages`?n(`添加包`,`Add package`):n(`手动配置技能`,`Configure skills manually`)}),(w.kind===`packages`?te:T).length>0&&(0,F.jsx)(`ul`,{children:(w.kind===`packages`?te:T).map(e=>(0,F.jsxs)(`li`,{className:`pi-config-item`,children:[(0,F.jsxs)(`div`,{className:`pi-resource-main`,children:[(0,F.jsx)(`code`,{title:e,children:e}),w.kind===`packages`&&(0,F.jsx)(`small`,{children:n(`已配置,但未发现安装目录`,`Configured, but installation directory was not found`)}),w.kind!==`packages`&&Vk(e)&&(0,F.jsx)(`small`,{className:`pi-config-warning`,children:n(`未加载:包来源请在“包与扩展”中添加。`,`Not loaded: add package sources under Packages & extensions.`)})]}),(0,F.jsxs)(`div`,{className:`pi-resource-actions`,children:[w.kind!==`packages`&&Vk(e)&&(0,F.jsx)(`button`,{type:`button`,disabled:g,onClick:()=>re(e),children:n(`转到包`,`Go to packages`)}),(0,F.jsx)(`button`,{type:`button`,disabled:g,"aria-label":`${n(`移除`,`Remove`)} ${e}`,onClick:()=>{C(w.kind,`remove`,e)},children:n(`移除`,`Remove`)})]})]},e))}),(0,F.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),D&&!O&&C(w.kind,`add`,D)},children:[(0,F.jsx)(`input`,{"aria-label":`${n(`添加`,`Add `)}${w.title}`,"aria-invalid":O||void 0,"aria-describedby":O?`pi-config-source-help`:void 0,placeholder:w.placeholder,value:d[w.kind],onChange:e=>p(t=>({...t,[w.kind]:e.target.value}))}),(0,F.jsx)(`button`,{type:`submit`,disabled:g||!D||O,children:n(`添加`,`Add`)})]}),O&&(0,F.jsxs)(`p`,{id:`pi-config-source-help`,className:`pi-config-hint`,children:[n(`这是包来源,请在「包」中添加。`,`This is a package source. Add it under Packages.`),(0,F.jsx)(`button`,{type:`button`,onClick:()=>re(D),children:n(`转到包`,`Go to packages`)})]})]}),w.kind===`packages`&&(0,F.jsxs)(`section`,{className:`pi-settings-section`,"aria-label":n(`手动配置扩展路径`,`Configure extension paths manually`),children:[(0,F.jsx)(`h3`,{children:n(`扩展路径`,`Extension paths`)}),c.global.extensions.length>0&&(0,F.jsx)(`ul`,{children:c.global.extensions.map(e=>(0,F.jsxs)(`li`,{className:`pi-config-item`,children:[(0,F.jsxs)(`div`,{className:`pi-resource-main`,children:[(0,F.jsx)(`code`,{title:e,children:e}),Vk(e)&&(0,F.jsx)(`small`,{className:`pi-config-warning`,children:n(`未加载:包来源不能作为扩展路径,请在上方添加包。`,`Not loaded: package sources cannot be extension paths. Add the package above.`)})]}),(0,F.jsxs)(`div`,{className:`pi-resource-actions`,children:[Vk(e)&&(0,F.jsx)(`button`,{type:`button`,disabled:g,onClick:()=>re(e),children:n(`填入包`,`Use as package`)}),(0,F.jsx)(`button`,{type:`button`,disabled:g,onClick:()=>{C(`extensions`,`remove`,e)},children:n(`移除`,`Remove`)})]})]},e))}),(0,F.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),ne&&!A&&C(`extensions`,`add`,ne)},children:[(0,F.jsx)(`input`,{"aria-label":n(`添加扩展路径`,`Add extension path`),"aria-invalid":A||void 0,"aria-describedby":A?`pi-extension-source-help`:void 0,placeholder:n(`扩展文件或目录路径`,`Extension file or directory path`),value:d.extensions,onChange:e=>p(t=>({...t,extensions:e.target.value}))}),(0,F.jsx)(`button`,{type:`submit`,disabled:g||!ne||A,children:n(`添加扩展`,`Add extension`)})]}),A&&(0,F.jsxs)(`p`,{id:`pi-extension-source-help`,className:`pi-config-hint`,children:[n(`这是包来源,请使用上方的“添加包”输入框。`,`This is a package source. Use the Add package field above.`),(0,F.jsx)(`button`,{type:`button`,onClick:()=>re(ne),children:n(`填入包`,`Use as package`)})]})]})]}):v?(0,F.jsx)(`p`,{role:`status`,children:n(`正在读取设置…`,`Loading settings…`)}):(0,F.jsx)(`button`,{className:`pi-settings-retry`,type:`button`,onClick:()=>{S()},children:n(`重试读取设置`,`Retry loading settings`)})]},w.kind)]})}function Uk({size:e=24}){return(0,F.jsxs)(`svg`,{"aria-hidden":`true`,width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,style:{display:`block`,flexShrink:0},children:[(0,F.jsx)(`path`,{d:`m14.5 4.5 5 5M4 20l5.3-1.3L20 8a2.8 2.8 0 0 0-4-4L5.3 14.7 4 20Z`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,F.jsx)(`path`,{d:`m5.5 14.5 4 4M8 15l8-8`,stroke:`currentColor`,strokeWidth:`1.2`,strokeLinecap:`round`})]})}var Wk={page:`_page_1bt34_2`,pageHead:`_pageHead_1bt34_4`,breadcrumb:`_breadcrumb_1bt34_7`,refresh:`_refresh_1bt34_8`,back:`_back_1bt34_8`,danger:`_danger_1bt34_8`,scope:`_scope_1bt34_12`,error:`_error_1bt34_13`,notice:`_notice_1bt34_13`,search:`_search_1bt34_16`,group:`_group_1bt34_17`,cards:`_cards_1bt34_20`,card:`_card_1bt34_20`,artwork:`_artwork_1bt34_23`,cardMain:`_cardMain_1bt34_24`,cardOpen:`_cardOpen_1bt34_25`,dot:`_dot_1bt34_31`,cardEnd:`_cardEnd_1bt34_33`,switch:`_switch_1bt34_34`,thumb:`_thumb_1bt34_36`,detail:`_detail_1bt34_40`,detailHead:`_detailHead_1bt34_41`},Gk={pluginId:`@chengzhiyi/pi-excalidraw`,name:`Excalidraw`,official:!0,icon:`drawing`,installed:!1,enabled:!1,phase:`not-installed`};async function Kk(e,t,n){let r=ve(),{response:i}=await s(`/api/hosted-plugins${e}`,{method:t===void 0?`GET`:`POST`,credentials:`same-origin`,signal:n,headers:{...r?{Authorization:`Bearer ${r}`}:{},...t===void 0?{}:{"Content-Type":`application/json`}},body:t===void 0?void 0:JSON.stringify(t)}),a=await i.json();if(!i.ok)throw Object.assign(Error(a.error?.message??a.error??`Hosted plugin request failed (${i.status})`),{status:i.status,code:a.error?.code??a.errorCode,reason:a.error?.reason??a.reason});return a}var qk={catalog:e=>Kk(``,void 0,e),manage:e=>Kk(`/manage`,e),action:e=>Kk(`/action`,e),decide:(e,t)=>Kk(`/approvals`,{id:e,decision:t}),secret:(e,t,n)=>Kk(`/secrets`,{pluginId:e,name:t,value:n}),signIn:e=>Kk(`/secrets`,e),pendingViews:e=>Kk(`/views`,{operation:`list-pending`,pluginId:e}),view:(e,t)=>Kk(`/views`,e,t)},Jk={section:`_section_1qkpy_1`,attention:`_attention_1qkpy_5`,notice:`_notice_1qkpy_6`,error:`_error_1qkpy_7`,actions:`_actions_1qkpy_8`,configuration:`_configuration_1qkpy_13`,rowActions:`_rowActions_1qkpy_14`};function Yk({pluginId:e,t}){let[n,r]=(0,P.useState)(null),[i,a]=(0,P.useState)(null),[o,s]=(0,P.useState)(``),[c,l]=(0,P.useState)(!1),[u,d]=(0,P.useState)(0);(0,P.useEffect)(()=>{let t=!0;return qk.pendingViews(e).then(e=>{t&&r(e.views)}).catch(e=>{t&&s(String(e))}),()=>{t=!1}},[e,u]);let f=async e=>{l(!0),s(``);try{await qk.view({pluginId:e.pluginId,sessionId:e.sessionId,generation:e.generation,mountId:e.mountId,viewToken:e.viewToken,operation:`discard`,confirmation:`discard-unconfirmed-edits`}),a(null),d(e=>e+1)}catch(e){s(String(e))}finally{l(!1)}};return!n?.length&&!o?null:(0,F.jsxs)(`div`,{className:Jk.error,"data-pending-views":!0,children:[(0,F.jsx)(`p`,{children:t(`宿主仍持有以下视图。若原窗口已关闭,可丢弃该视图后重试;仍打开的窗口请先保存并关闭。丢弃不会保存内容,无法找回的修改可能永久丢失。`,`The host still holds these views. If the original window is closed, discard the view and retry; save and close windows that are still open first. Discarding does not save content; unrecovered edits may be permanently lost.`)}),n?.map(e=>(0,F.jsxs)(`div`,{children:[(0,F.jsxs)(`code`,{children:[e.kind,` · `,e.mountId,` · `,t(`会话`,`session`),` `,e.sessionId,e.dirty||e.busy?` · ${t(`有未确认修改`,`unconfirmed edits`)}`:``]}),` `,i===e.viewToken?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(EO,{variant:`outline`,size:`sm`,disabled:c,onClick:()=>void f(e),children:t(`确认丢弃`,`Confirm discard`)}),` `,(0,F.jsx)(EO,{variant:`outline`,size:`sm`,disabled:c,onClick:()=>a(null),children:t(`取消`,`Cancel`)})]}):(0,F.jsx)(EO,{variant:`outline`,size:`sm`,disabled:c,onClick:()=>a(e.viewToken),children:t(`丢弃此视图`,`Discard this view`)})]},e.viewToken)),o&&(0,F.jsx)(`p`,{role:`alert`,children:o})]})}function Xk({size:e=24}){return(0,F.jsx)(`svg`,{"aria-hidden":`true`,width:e,height:e,viewBox:`0 0 16 16`,fill:`currentColor`,style:{display:`block`,flexShrink:0},children:(0,F.jsx)(`path`,{d:`M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82a7.6 7.6 0 0 1 4 0c1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8Z`})})}function Zk({card:e,size:t=24}){let n=e.icon??(e.pluginId===Gk.pluginId?Gk.icon:void 0);return(0,F.jsx)(n===`drawing`?Uk:n===`github`?Xk:fe,{size:t})}function Qk(e,t,n){let r=(e,n)=>t===`zh`?e:n;return e===`uninstall`?{title:r(`卸载 ${n}?`,`Uninstall ${n}?`),description:r(`保存成功后将关闭相关视图并卸载插件。工作区文件和插件数据会保留,可重新安装后继续使用;保存失败时不会卸载。`,`After saving successfully, related views close and the plugin is uninstalled. Workspace files and plugin data are retained for reinstallation. A failed save stops uninstallation.`),confirm:r(`卸载`,`Uninstall`)}:e===`disable`?{title:r(`停用 ${n}?`,`Disable ${n}?`),description:r(`保存成功后将关闭相关视图并停用插件。插件仍保持安装,工作区文件和插件数据会保留;保存失败时不会停用。`,`After saving successfully, related views close and the plugin is disabled. It remains installed, with workspace files and plugin data retained. A failed save stops disabling.`),confirm:r(`停用`,`Disable`)}:{title:r(`立即更新 ${n} 并重新打开?`,`Update ${n} and reopen now?`),description:r(`全部视图保存成功后将更新插件并重新打开视图,撤销/重做历史会清空。工作区文件和插件数据会保留;保存失败时不会更新。`,`After all views save successfully, update the plugin and reopen its views. Undo/redo history will be cleared. Workspace files and plugin data are retained. A failed save stops the update.`),confirm:r(`更新并重新打开`,`Update and reopen`)}}function $k({card:e,t,onCatalog:n,disabled:r}){let[i,a]=(0,P.useState)({}),[o,s]=(0,P.useState)(``),[c,l]=(0,P.useState)(null),[u,d]=(0,P.useState)(!1),f=(0,P.useRef)(!0);if((0,P.useEffect)(()=>(f.current=!0,()=>{f.current=!1}),[]),(0,P.useEffect)(()=>{if(!c)return;let e=!1;return(async()=>{for(;!e&&f.current;){if(await new Promise(e=>setTimeout(e,3e3)),e||!f.current)return;try{let e=await qk.signIn({auth:`poll`,deviceId:c.deviceId});if(e.status===`granted`&&e.catalog){n(e.catalog),l(null),s(t(`已授权。`,`Authorized.`));return}if(e.status===`denied`||e.status===`expired`){l(null),s(e.status===`denied`?t(`授权已被拒绝。`,`Authorization was denied.`):t(`授权已过期,请重试。`,`Authorization expired. Try again.`));return}}catch(e){l(null),s(e instanceof Error?e.message:String(e));return}}})(),()=>{e=!0}},[c]),!e.secrets?.length)return null;let p=async(r,i)=>{s(``);try{n(await qk.secret(e.pluginId,r,i)),a(e=>({...e,[r]:``})),s(i===null?t(`已移除。`,`Removed.`):t(`已保存。`,`Saved.`))}catch(e){s(e instanceof Error?e.message:String(e))}},m=async t=>{s(``);try{let n=await qk.signIn({auth:`start`,pluginId:e.pluginId,name:t});d(!1),l({name:t,deviceId:n.deviceId,userCode:n.userCode,verificationUri:n.verificationUri})}catch(e){s(e instanceof Error?e.message:String(e))}},h=async e=>{d(await tf(e))},g=e=>{window.open(e.verificationUri,`_blank`,`noopener,noreferrer`),h(e.userCode)},_=()=>{c&&qk.signIn({auth:`cancel`,deviceId:c.deviceId}).catch(()=>{}),l(null)};return(0,F.jsxs)(`section`,{className:Jk.configuration,children:[(0,F.jsx)(`h2`,{children:t(`GitHub 授权`,`GitHub authorization`)}),(0,F.jsx)(`p`,{className:Wk.scope,children:t(`令牌只保存在本机,由主程序代为发起请求;插件进程和页面永远读不到它。`,`The token is stored on this machine and used by the host on the plugin's behalf; plugin code and pages can never read it.`)}),e.secrets.map(e=>(0,F.jsxs)(`div`,{className:Jk.configuration,children:[(0,F.jsxs)(`div`,{className:Jk.actions,children:[(0,F.jsx)(`span`,{role:`status`,children:e.configured?t(`已授权`,`Authorized`):t(`未授权`,`Not authorized`)}),e.signIn===`browser`&&(0,F.jsx)(EO,{variant:`outline`,size:`sm`,disabled:r||!!c,onClick:()=>void m(e.name),children:e.configured?t(`重新授权`,`Re-authorize`):t(`在浏览器中授权 GitHub`,`Authorize with GitHub`)}),e.signIn===`token-page`&&e.createUrl&&(0,F.jsx)(EO,{variant:`outline`,size:`sm`,disabled:r,onClick:()=>window.open(e.createUrl,`_blank`,`noopener,noreferrer`),children:t(`打开 GitHub 创建令牌`,`Open GitHub to create a token`)}),e.configured&&(0,F.jsx)(EO,{variant:`outline`,size:`sm`,disabled:r,onClick:()=>void p(e.name,null),children:t(`移除`,`Remove`)})]}),c?.name===e.name&&(0,F.jsxs)(`div`,{className:Wk.scope,role:`status`,children:[(0,F.jsxs)(`ol`,{style:{margin:0,paddingLeft:20,display:`grid`,gap:10},children:[(0,F.jsxs)(`li`,{children:[t(`复制下面的验证码`,`Copy this code`),(0,F.jsxs)(`div`,{className:Jk.actions,style:{marginTop:6},children:[(0,F.jsx)(`code`,{style:{fontSize:28,letterSpacing:4,fontWeight:600,padding:`6px 14px`,border:`1px solid currentColor`,borderRadius:8,userSelect:`all`},children:c.userCode}),(0,F.jsx)(EO,{variant:`outline`,size:`sm`,onClick:()=>void h(c.userCode),children:u?t(`已复制`,`Copied`):t(`复制`,`Copy`)})]})]}),(0,F.jsxs)(`li`,{children:[t(`打开 GitHub 授权页,粘贴验证码并点击 Authorize`,`Open GitHub, paste the code and click Authorize`),(0,F.jsx)(`div`,{className:Jk.actions,style:{marginTop:6},children:(0,F.jsx)(EO,{size:`sm`,onClick:()=>g(c),children:t(`复制验证码并打开 GitHub`,`Copy code and open GitHub`)})})]})]}),(0,F.jsxs)(`div`,{className:Jk.actions,style:{marginTop:10},children:[(0,F.jsx)(`span`,{children:t(`等待授权中… 完成后这里会自动更新。`,`Waiting for authorization… this updates automatically.`)}),(0,F.jsx)(EO,{variant:`outline`,size:`sm`,onClick:_,children:t(`取消`,`Cancel`)})]})]}),(0,F.jsxs)(`details`,{open:e.signIn===`token-page`&&!e.configured,children:[(0,F.jsx)(`summary`,{children:e.signIn===`token-page`?t(`创建后在此粘贴令牌(仅限目标仓库的 fine-grained token,Issues、Pull requests、Contents 读写)`,`Paste the token here after creating it (fine-grained, limited to the target repository, Issues / Pull requests / Contents read-write)`):t(`改用手动粘贴令牌`,`Paste a token instead`)}),(0,F.jsxs)(`div`,{className:Jk.actions,children:[(0,F.jsx)(`input`,{type:`password`,autoComplete:`off`,"aria-label":e.name,value:i[e.name]??``,onChange:t=>a(n=>({...n,[e.name]:t.target.value}))}),(0,F.jsx)(EO,{variant:`outline`,size:`sm`,disabled:r||!(i[e.name]??``).trim(),onClick:()=>void p(e.name,(i[e.name]??``).trim()),children:t(`保存`,`Save`)})]})]})]},e.name)),o&&(0,F.jsx)(`p`,{role:`status`,className:Wk.scope,children:o})]})}function eA(e,t,n){let r={metadata_not_found:n(`官方插件暂未发布,暂不可安装。稍后可重新检查。`,`The official package is not currently published. Check again later.`),tarball_not_found:n(`发行文件暂不可用。请重新检查或稍后重试。`,`The release file is unavailable. Check again or retry later.`),no_compatible_version:n(`暂无适用于此软件版本的插件。稍后可重新检查。`,`No compatible release for this app version. Check again later.`),registry_unreachable:n(`暂时无法访问下载服务。请检查网络后重试。`,`Cannot reach the download service. Check your network and retry.`),download_cancelled:n(`下载已取消。`,`Download cancelled.`),view_barrier:n(`尚未完成所有视图的保存确认,操作已停止。请先处理本页的刷新前视图记录,并检查仍打开的编辑器,然后重试。`,`Save confirmation is still pending for some views, so the operation stopped. Review previous-view records on this page and any open editors, then retry.`),runtime_owned:n(`插件运行时被其他宿主或遗留锁占用,当前无法打开或卸载。请停止所有宿主并校验备份后,按恢复说明处理;重新安装不会清除此锁。`,`Another host or a retained ownership lock blocks this runtime, including opening and uninstalling. Stop all hosts, verify a backup and follow recovery instructions; reinstalling does not clear the lock.`)}[e.code??``]??n(`操作未完成。请查看诊断信息后重试。`,`Operation did not finish. Review diagnostics and retry.`);return(t&&[`metadata_not_found`,`tarball_not_found`,`no_compatible_version`,`registry_unreachable`,`download_cancelled`].includes(e.code??``)?n(`更新未完成,当前插件及数据已保留。`,`Update did not finish; current plugin and data retained. `):``)+r}function tA({locale:e,generation:t=0,reload:n=0,query:r=``,selectedId:i,visible:a=!0,disabled:o=!1,onSelect:s,onBusyChange:c,onMatchCountChange:l}){let u=(t,n)=>e===`zh`?t:n,[d,f]=(0,P.useState)({plugins:[Gk],offline:!0}),[p,m]=(0,P.useState)(!1),[h,g]=(0,P.useState)(!0),[_,v]=(0,P.useState)(!1),y=(0,P.useRef)(!1),b=(0,P.useRef)(0),x=(0,P.useRef)(new Set);(0,P.useEffect)(()=>{for(let e of d.plugins)e.installed&&x.current.add(e.pluginId)},[d]);let[S,C]=(0,P.useState)(null),[w,T]=(0,P.useState)(null),[E,D]=(0,P.useState)(null),[O,k]=(0,P.useState)(``),[ee,te]=(0,P.useState)(0),[ne,A]=(0,P.useState)(null),re=ne?Qk(ne.operation,e,ne.card.name):null,ie=e=>({message:e instanceof Error?e.message:String(e),code:e?.code});(0,P.useEffect)(()=>{if(y.current)return;let e=++b.current,t=new AbortController;return g(!0),D(null),qk.catalog(t.signal).then(t=>{e===b.current&&(f(t),m(!0),T(null))}).catch(n=>{!t.signal.aborted&&e===b.current&&(T(ie(n)),f(e=>({...e,offline:!0})))}).finally(()=>{e===b.current&&g(!1)}),()=>{t.abort()}},[t,n,ee]);let j=async(e,t,n=!1)=>{if(y.current||o||h)return;y.current=!0,++b.current,A(null);let r=[`install`,`update`,`check`].includes(t)?crypto.randomUUID():void 0;C(r?{pluginId:e.pluginId,id:r}:null),v(!0),c(!0),D(null),k(``);try{let i=await qk.manage({pluginId:e.pluginId,operation:t,...r?{downloadId:r}:{},...n?{reopenEditors:!0}:{}});f(i),m(!0),T(null),k(i.plugins.some(e=>e.pendingVersion)?u(`更新已准备好,关闭编辑器后生效。`,`Update ready. Close editors to apply.`):u(`操作完成。`,`Done.`)),window.dispatchEvent(new Event(`pi:hosted-catalog-changed`))}catch(t){D({id:e.pluginId,problem:ie(t)});try{f(await qk.catalog()),m(!0),window.dispatchEvent(new Event(`pi:hosted-catalog-changed`))}catch{}}finally{y.current=!1,v(!1),c(!1),C(null)}},ae=(e,t)=>{t===`disable`||t===`uninstall`?A({card:e,operation:t}):j(e,t)},oe=d.plugins.some(e=>e.pluginId===Gk.pluginId)?d.plugins:[...d.plugins,Gk],M=oe.find(e=>e.pluginId===i),se=oe.filter(e=>`${e.name} ${e.pluginId} ${le(e)}`.toLowerCase().includes(r.trim().toLowerCase()));(0,P.useEffect)(()=>{l(se.length)},[se.length,l]);let ce=_||h||o||!p||!!d.offline;function le(t){return t.contribution?.entry.description[e]??t.description?.[e]??(t.pluginId===Gk.pluginId?u(`绘制、编辑手绘图表,并将图稿保存到工作区。`,`Draw and edit hand-drawn diagrams, and save them to your workspace.`):u(`按需下载安装的官方插件。`,`An official plugin available on demand.`))}let ue=e=>`${e.name}${e.official?u(`(官方)`,` (Official)`):``}`,de=e=>E?.id===e.pluginId?E.problem:e.error?{code:e.errorCode,message:e.error}:e.updateDiagnostic?.status===`failed`?e.updateDiagnostic:null,fe=e=>p?`${e.installed?u(`已安装`,`Installed`):u(`未安装`,`Not installed`)} · ${e.enabled?u(`已启用`,`Enabled`):u(`未启用`,`Disabled`)}${e.version?` ${e.version}`:``}${e.enabled&&e.phase!==`active`?u(` · 运行时不可用`,` · Runtime unavailable`):``}`:u(`安装状态未知 · 启用状态未知`,`Installation unknown · Enablement unknown`),pe=e=>(0,F.jsx)(`button`,{type:`button`,role:`switch`,className:Wk.switch,"aria-label":u(`启用 ${e.name}`,`Enable ${e.name}`),"aria-checked":p&&e.enabled,disabled:ce||!e.installed,title:p?e.installed?void 0:u(`请先下载插件`,`Download the plugin first`):u(`请先读取插件状态`,`Read plugin status first`),onClick:()=>ae(e,e.enabled?`disable`:`enable`),children:(0,F.jsx)(`span`,{className:Wk.thumb})}),me=e=>{let t=de(e),n=!e.installed&&!!t&&[`metadata_not_found`,`tarball_not_found`,`no_compatible_version`].includes(t.code??``);return(0,F.jsx)(EO,{variant:`outline`,size:`sm`,disabled:ce||n,onClick:()=>ae(e,e.pendingVersion?`retry`:e.installed?`update`:`install`),children:e.pendingVersion?u(`应用待更新版本`,`Apply pending update`):e.installed?u(`更新`,`Update`):n?u(`暂不可下载`,`Unavailable`):e.hasRetainedData||x.current.has(e.pluginId)?u(`重新安装`,`Reinstall`):u(`下载`,`Download`)})};return(0,P.useEffect)(()=>{if(!E||M)return;let e=oe.find(e=>e.pluginId===E.id);zt({key:`hosted-operation-${E.id}`,message:`${e?`${ue(e)}:`:``}${eA(E.problem,!!e?.installed,u)}`,detail:[E.problem.code,E.problem.message].filter(Boolean).join(`: `),detailLabel:u(`诊断信息`,`Diagnostics`)})},[E]),(0,F.jsxs)(`section`,{className:Jk.section,"data-hosted-management":!0,"aria-busy":_||h,style:a?void 0:{display:`none`},children:[!M&&(0,F.jsxs)(`h2`,{children:[u(`官方插件`,`Official plugins`),` `,(0,F.jsx)(`span`,{children:se.length})]}),w&&(0,F.jsxs)(`div`,{role:`alert`,className:Jk.error,children:[u(`无法读取插件状态,请重试。`,`Cannot read plugin status. Please retry.`),(0,F.jsxs)(`details`,{children:[(0,F.jsx)(`summary`,{children:u(`诊断信息`,`Diagnostics`)}),w.message]}),(0,F.jsx)(EO,{variant:`outline`,size:`sm`,disabled:_||h||o,onClick:()=>te(e=>e+1),children:u(`重试`,`Retry`)})]}),d.dev&&(0,F.jsxs)(`div`,{"data-hosted-dev":!0,children:[d.dev.notices.map((e,t)=>(0,F.jsxs)(`div`,{className:e.level===`info`?Jk.notice:Jk.error,role:e.level===`error`?`alert`:`status`,children:[(0,F.jsxs)(`strong`,{children:[u(`开发模式`,`Dev mode`),e.pluginId?` · ${e.pluginId}`:``]}),`: `,e.message]},t)),d.dev.sources.map(e=>(0,F.jsxs)(`p`,{className:Jk.notice,role:`status`,"data-hosted-dev-source":e.pluginId,children:[u(`开发目录`,`Dev directory`),` · `,(0,F.jsx)(`code`,{children:e.root}),` · `,e.state,e.version?` ${e.version}`:``,e.message?` — ${e.message}`:``]},e.pluginId))]}),O&&(0,F.jsx)(`p`,{className:Jk.notice,role:`status`,children:O}),S&&(0,F.jsx)(EO,{variant:`outline`,onClick:()=>{qk.manage({pluginId:S.pluginId,operation:`cancel-download`,downloadId:S.id}).then(()=>k(u(`已请求取消,已完成的安装不会回滚。`,`Cancellation requested; committed installations are not rolled back.`))).catch(e=>D({id:S.pluginId,problem:ie(e)}))},children:u(`取消下载(不回滚已提交安装)`,`Cancel download (no rollback after commit)`)}),M?(0,F.jsxs)(`div`,{className:Wk.detail,"data-hosted-detail":M.pluginId,children:[(0,F.jsxs)(`div`,{className:Wk.detailHead,children:[(0,F.jsx)(`span`,{className:Wk.artwork,"aria-hidden":`true`,children:(0,F.jsx)(Zk,{card:M,size:30})}),(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`strong`,{children:ue(M)}),(0,F.jsx)(`p`,{children:le(M)})]}),pe(M)]}),(0,F.jsxs)(`dl`,{children:[(0,F.jsx)(`dt`,{children:u(`插件标识`,`Plugin ID`)}),(0,F.jsx)(`dd`,{children:(0,F.jsx)(`code`,{children:M.pluginId})}),(0,F.jsx)(`dt`,{children:u(`来源`,`Source`)}),(0,F.jsx)(`dd`,{children:u(`按需下载的官方插件`,`Official on-demand package`)}),(0,F.jsx)(`dt`,{children:u(`状态`,`Status`)}),(0,F.jsx)(`dd`,{children:fe(M)}),M.availableVersion&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`dt`,{children:u(`可用版本`,`Available release`)}),(0,F.jsx)(`dd`,{children:M.availableVersion})]}),M.pendingVersion&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`dt`,{children:u(`待更新版本`,`Pending release`)}),(0,F.jsx)(`dd`,{children:M.pendingVersion})]})]}),((e,t)=>{let n=de(e),r=e.updateDiagnostic;return n?(0,F.jsxs)(`div`,{className:Jk.error,role:`alert`,children:[eA(n,e.installed,u),(0,F.jsxs)(`details`,{children:[(0,F.jsx)(`summary`,{children:u(`诊断信息`,`Diagnostics`)}),(0,F.jsx)(`code`,{children:n.code}),(0,F.jsx)(`p`,{children:n.message}),r&&(0,F.jsxs)(`p`,{children:[r.checkedAt,` · `,r.hostVersion]}),/lock|owned/i.test(n.message)&&(0,F.jsx)(`p`,{children:u(`停止所有程序并备份后,按 docs/hosted-update-recovery.md 恢复。此页面不会清锁。`,`Stop all hosts and back up data before following docs/hosted-update-recovery.md. This page never clears locks.`)})]}),n.code===`view_barrier`&&(0,F.jsx)(Yk,{pluginId:e.pluginId,t:u})]}):null})(M,!0),(0,F.jsx)($k,{card:M,t:u,disabled:ce,onCatalog:e=>{f(e),window.dispatchEvent(new Event(`pi:hosted-catalog-changed`))}}),(0,F.jsxs)(`section`,{className:Jk.configuration,children:[(0,F.jsx)(`h2`,{children:u(`配置与更新`,`Configuration & updates`)}),(0,F.jsx)(`p`,{className:Wk.scope,children:M.icon===`drawing`||M.pluginId===Gk.pluginId?u(`无需额外配置。启用后,可从工作区侧栏打开,也可查看对话中的图稿。图稿保存在工作区,停用或卸载不会删除文件和插件数据。`,`No additional configuration is required. Once enabled, open it from the workspace sidebar or view diagrams in conversations. Disabling or uninstalling retains workspace files and plugin data.`):u(`启用后从工作区侧栏打开。停用或卸载不会删除插件数据。`,`Once enabled, open it from the workspace sidebar. Disabling or uninstalling retains plugin data.`)}),(0,F.jsx)(`p`,{className:Wk.scope,children:u(`兼容的插件可独立更新;软件升级仅在协议不兼容时协调插件版本。`,`Compatible plugins update independently. App upgrades coordinate plugins only when their protocol is incompatible.`)}),(0,F.jsx)(`p`,{className:Wk.scope,children:u(`停用或卸载前会先保存并关闭相关视图;保存失败时不会继续。`,`Disabling or uninstalling first saves and closes related views; a failed save stops the operation.`)}),M.pendingVersion&&(0,F.jsxs)(`p`,{className:Wk.scope,role:`status`,children:[u(`关闭编辑器后更新至:`,`Close editors to update to: `),M.pendingVersion]}),!de(M)&&M.updateDiagnostic?.status===`up-to-date`&&!M.pendingVersion&&(0,F.jsx)(`p`,{className:Wk.scope,children:u(`兼容版本检查已完成。`,`Compatible release check complete.`)}),(0,F.jsxs)(`div`,{className:Jk.actions,children:[me(M),(0,F.jsx)(EO,{variant:`outline`,size:`sm`,disabled:ce,onClick:()=>ae(M,`check`),children:u(`检查更新`,`Check updates`)}),M.installed&&(0,F.jsx)(EO,{variant:`outline`,size:`sm`,disabled:ce,onClick:()=>ae(M,`uninstall`),children:u(`卸载`,`Uninstall`)}),M.pendingVersion&&(0,F.jsx)(EO,{variant:`outline`,size:`sm`,disabled:ce,onClick:()=>A({card:M,operation:`update`,reopen:!0}),children:u(`立即更新并重新打开`,`Update and reopen now`)})]})]})]}):(0,F.jsx)(`ul`,{className:Wk.cards,children:se.map(e=>(0,F.jsxs)(`li`,{className:Wk.card,"data-hosted-card":e.pluginId,children:[(0,F.jsx)(`span`,{className:Wk.artwork,"aria-hidden":`true`,children:(0,F.jsx)(Zk,{card:e,size:30})}),(0,F.jsxs)(`div`,{className:Wk.cardMain,children:[(0,F.jsx)(`button`,{className:Wk.cardOpen,type:`button`,onClick:()=>s({id:e.pluginId,name:e.name}),children:ue(e)}),(0,F.jsx)(`p`,{children:le(e)}),(0,F.jsxs)(`small`,{children:[(0,F.jsx)(`span`,{className:Wk.dot,"data-enabled":p&&e.enabled}),_?u(`正在应用…`,`Applying…`):fe(e),!_&&de(e)&&(0,F.jsx)(`span`,{className:Jk.attention,children:u(` · 需要处理`,` · Needs attention`)})]}),e.pendingVersion?(0,F.jsxs)(`small`,{children:[u(`关闭编辑器后更新至:`,`Close editors to update to: `),e.pendingVersion]}):e.availableVersion&&e.availableVersion!==e.version&&(0,F.jsxs)(`small`,{children:[u(`可用版本:`,`Available release: `),e.availableVersion]})]}),(0,F.jsxs)(`div`,{className:`${Wk.cardEnd} ${Jk.rowActions}`,children:[me(e),pe(e),(0,F.jsx)(`span`,{"aria-hidden":`true`,children:`›`})]})]},e.pluginId))}),(0,F.jsx)(OO,{open:ne!==null,onClose:()=>A(null),title:re?.title??``,closeLabel:u(`关闭`,`Close`),description:re?.description,footer:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(EO,{variant:`outline`,onClick:()=>A(null),children:u(`取消`,`Cancel`)}),(0,F.jsx)(EO,{variant:`primary`,disabled:ce,onClick:()=>{ne&&j(ne.card,ne.operation,ne.reopen)},children:re?.confirm})]})})]})}function nA({getPluginManagement:e,togglePlugin:t,generation:n=0,recovery:r}){let i=l(),a=(e,t)=>f(i,e,t),o=e=>typeof e==`string`?e:e[i],[s,c]=(0,P.useState)(null),[u,p]=(0,P.useState)(null),[m,h]=(0,P.useState)(null),[g,v]=(0,P.useState)(!1),[y,b]=(0,P.useState)(1),[x,S]=(0,P.useState)(0),[C,w]=(0,P.useState)(``),[T,E]=(0,P.useState)(null),[D,O]=(0,P.useState)(!0),[k,ee]=(0,P.useState)(``),[te,ne]=(0,P.useState)(``),[A,re]=(0,P.useState)(null),ie=(0,P.useRef)(!1),j=(0,P.useRef)(!1),ae=(0,P.useRef)(n),oe=(0,P.useRef)(!0),M=async(t=!0)=>{if(ie.current)j.current=!0;else{ie.current=!0,O(!0),t&&(ee(``),S(e=>e+1));try{let t=await e();oe.current&&c(t)}catch(e){oe.current&&ee(e instanceof Error?e.message:a(`无法读取插件`,`Could not load plugins`))}finally{ie.current=!1,oe.current&&O(!1),j.current&&oe.current&&(j.current=!1,M(!1))}}};(0,P.useEffect)(()=>(oe.current=!0,M(),()=>{oe.current=!1}),[]),(0,P.useEffect)(()=>{ae.current!==n&&(ae.current=n,M(!1))},[n]);let se=async e=>{if(s&&!ie.current){ie.current=!0,E(e.id),ee(``),ne(``),re(null);try{let n=await t({id:e.id,enabled:!e.enabled,expected:s.revision});oe.current&&(c(n),ne(a(`插件配置已保存并生效`,`Plugin settings saved and applied`)))}catch(e){oe.current&&ee((e instanceof Error?e.message:a(`保存失败`,`Could not save`))+a(`。请刷新确认状态;操作不会自动重试。`,`. Refresh to verify the state; this operation is not retried automatically.`))}finally{ie.current=!1,oe.current&&E(null),j.current&&oe.current&&(j.current=!1,M(!1))}}},le=e=>{e.id===d.terminal&&e.enabled?re(e):se(e)},ue=e=>(0,F.jsx)(`button`,{type:`button`,role:`switch`,className:Wk.switch,"aria-label":a(`启用 ${o(e.name)}`,`Enable ${o(e.name)}`),"aria-checked":e.enabled,disabled:D||T!==null||g||!e.managed,title:e.managed?void 0:a(`请在包与扩展中管理 Pi 运行时`,`Manage the Pi runtime under Packages & extensions`),onClick:()=>le(e),children:(0,F.jsx)(`span`,{className:Wk.thumb})}),de=e=>e.id===d.git?(0,F.jsx)(ce,{size:30}):e.id===d.terminal?(0,F.jsx)(`span`,{children:`›_`}):e.id===d.files?(0,F.jsx)(_,{kind:`folder`,size:30}):e.id===d.diagrams?(0,F.jsx)(Uk,{size:30}):(0,F.jsx)(`span`,{children:`◇`}),fe=s?.items.find(e=>e.id===u),pe=s?.items.filter(e=>`${o(e.name)} ${o(e.description)} ${e.id}`.toLowerCase().includes(C.trim().toLowerCase()))??[];return(0,F.jsxs)(`section`,{className:Wk.page,"data-plugin-panel":!0,"aria-busy":D||T!==null,children:[(0,F.jsxs)(`header`,{className:Wk.pageHead,children:[(0,F.jsxs)(`div`,{children:[(fe||m)&&(0,F.jsx)(`div`,{className:Wk.breadcrumb,children:(0,F.jsx)(`button`,{type:`button`,onClick:()=>{p(null),h(null)},children:a(`‹ 插件`,`‹ Plugins`)})}),(0,F.jsx)(`h1`,{children:fe?o(fe.name):m?.name??a(`插件`,`Plugins`)}),(0,F.jsx)(`p`,{children:a(`管理此服务的可选能力,按需启用。`,`Manage optional capabilities on this service.`)})]}),(0,F.jsx)(`button`,{type:`button`,className:Wk.refresh,disabled:D||T!==null||g,onClick:()=>void M(),"aria-label":a(`刷新插件`,`Refresh plugins`),children:D?`…`:`↻`})]}),(0,F.jsx)(`p`,{className:Wk.scope,children:a(`全局设置 · 影响此服务的所有工作区和聊天;所有聊天空闲后才可修改。`,`Global settings · Applies to every workspace and chat on this service. Changes require all chats to be idle.`)}),r,k&&(0,F.jsx)(`p`,{className:Wk.error,role:`alert`,children:k}),te&&(0,F.jsx)(`p`,{className:Wk.notice,role:`status`,children:te}),D&&!s&&(0,F.jsx)(`p`,{role:`status`,children:a(`正在读取插件…`,`Loading plugins…`)}),!s&&!D&&(0,F.jsx)(`button`,{type:`button`,className:Wk.back,onClick:()=>void M(),children:a(`重试`,`Retry`)}),fe?(0,F.jsxs)(`div`,{className:Wk.detail,children:[(0,F.jsxs)(`div`,{className:Wk.detailHead,children:[(0,F.jsx)(`span`,{className:Wk.artwork,"aria-hidden":`true`,children:de(fe)}),(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`strong`,{children:o(fe.name)}),(0,F.jsx)(`p`,{children:o(fe.description)})]}),ue(fe)]}),(0,F.jsxs)(`dl`,{children:[(0,F.jsx)(`dt`,{children:a(`插件标识`,`Plugin ID`)}),(0,F.jsx)(`dd`,{children:(0,F.jsx)(`code`,{children:fe.id})}),(0,F.jsx)(`dt`,{children:a(`来源`,`Source`)}),(0,F.jsx)(`dd`,{children:fe.kind===`builtin`?a(`随应用内置`,`Bundled with the application`):a(`Pi 软件包`,`Pi package`)}),(0,F.jsx)(`dt`,{children:a(`状态`,`Status`)}),(0,F.jsx)(`dd`,{children:fe.enabled?a(`已启用`,`Enabled`):a(`已停用`,`Disabled`)}),fe.version&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`dt`,{children:a(`契约版本`,`Contract version`)}),(0,F.jsx)(`dd`,{children:fe.version})]})]}),(0,F.jsx)(`p`,{className:Wk.scope,children:fe.managed?a(`停用会移除入口、关闭相关标签并阻止该插件的后端请求。不会删除工作区文件或聊天记录。`,`Disabling removes entries, closes related tabs and blocks backend requests. Workspace files and chat history are not deleted.`):a(`此插件的 Pi 运行时由软件包管理。当前协议未提供独立、安全卸载该运行时的能力,因此这里仅展示状态,不提供假开关。`,`The Pi package owns this runtime. Its protocol does not expose independent safe teardown, so this page shows its status without a misleading toggle.`)}),fe.id===d.git&&(0,F.jsx)(`p`,{className:Wk.scope,children:a(`关闭 Git 面板不禁止 Agent 或其他终端执行系统 git。`,`Disabling the Git panel does not prevent an agent or another terminal from running system git.`)})]}):s&&!m&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`input`,{type:`search`,className:Wk.search,value:C,onChange:e=>w(e.target.value),placeholder:a(`搜索插件`,`Search plugins`),"aria-label":a(`搜索插件`,`Search plugins`)}),[`builtin`,`external`].map(e=>{let t=pe.filter(t=>t.kind===e);return t.length?(0,F.jsxs)(`section`,{className:Wk.group,children:[(0,F.jsxs)(`h2`,{children:[e===`builtin`?a(`内置能力`,`Built-in capabilities`):a(`已安装的 Web 插件`,`Installed Web plugins`),` `,(0,F.jsx)(`span`,{children:t.length})]}),(0,F.jsx)(`ul`,{className:Wk.cards,children:t.map(e=>(0,F.jsxs)(`li`,{className:Wk.card,"data-plugin-package":e.id,children:[(0,F.jsx)(`span`,{className:Wk.artwork,"aria-hidden":`true`,children:de(e)}),(0,F.jsxs)(`div`,{className:Wk.cardMain,children:[(0,F.jsx)(`button`,{className:Wk.cardOpen,type:`button`,onClick:()=>p(e.id),children:o(e.name)}),(0,F.jsx)(`p`,{children:o(e.description)}),(0,F.jsxs)(`small`,{children:[(0,F.jsx)(`span`,{className:Wk.dot,"data-enabled":e.enabled}),T===e.id?a(`正在应用…`,`Applying…`):e.enabled?a(`已启用`,`Enabled`):a(`已停用`,`Disabled`)]})]}),(0,F.jsxs)(`div`,{className:Wk.cardEnd,children:[ue(e),(0,F.jsx)(`span`,{"aria-hidden":`true`,children:`›`})]})]},e.id))})]},e):null}),!pe.length&&!y&&(0,F.jsx)(`p`,{className:Wk.scope,children:a(`没有匹配的插件`,`No matching plugins`)})]}),(0,F.jsx)(tA,{locale:i,generation:n,reload:x,query:C,selectedId:m?.id??null,visible:!fe,disabled:D||T!==null,onSelect:h,onBusyChange:v,onMatchCountChange:b}),(0,F.jsx)(OO,{open:A!==null,onClose:()=>re(null),title:a(`停用终端?`,`Disable Terminal?`),closeLabel:a(`关闭`,`Close`),description:a(`这会结束此服务所有聊天中的终端进程。未保存的 shell 工作可能丢失。`,`This ends terminal processes in every chat on this service. Unsaved shell work may be lost.`),footer:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`button`,{className:Wk.back,type:`button`,onClick:()=>re(null),children:a(`取消`,`Cancel`)}),(0,F.jsx)(`button`,{className:Wk.danger,type:`button`,onClick:()=>{A&&se(A)},children:a(`停用并结束终端`,`Disable and stop terminals`)})]})})]})}var rA={root:`_root_1ikfi_1`,trigger:`_trigger_1ikfi_2`,glyph:`_glyph_1ikfi_4`,dot:`_dot_1ikfi_5`,srOnly:`_srOnly_1ikfi_6`};function iA(e){let t=Ek();return t?(0,F.jsx)(oA,{...e,controller:t}):(0,F.jsx)(aA,{...e})}function aA(e){let t=Ck(e);return(0,F.jsx)(oA,{...e,controller:t})}function oA({wide:e,hideError:t,controller:n}){let r=l(),i=(e,t)=>f(r,e,t),{status:a,checking:o,installing:s,targetVersion:c,restartTimedOut:u,error:d,install:p}=n;if(Vt(`app-update`,t?null:d&&i(`升级未完成,当前版本和数据已保留。可稍后重试。`,`Update did not finish; the current version and data are retained. You can retry.`),d??void 0,i(`诊断信息`,`Diagnostics`)),!a?.available||!a.canRestart)return null;let m=s?i(`正在升级…`,`Updating…`):c?i(`正在重启…`,`Restarting…`):a.downgrade?i(`切换到稳定版`,`Switch to stable`):i(`下载升级`,`Download updates`),h=a.downgrade?i(`按更新偏好切换到稳定版,需要确认后重启`,`Switch to stable based on your preference; confirmation and restart required`):i(`下载并升级到新版本,服务将短暂重启`,`Download and update to the new version; the service will briefly restart`);return(0,F.jsxs)(`div`,{className:rA.root,children:[(0,F.jsx)(`div`,{className:`pi-settings-trigger-row ${e?``:`pi-settings-trigger-rail`}`,children:(0,F.jsx)(Xe,{label:h,children:(0,F.jsxs)(`button`,{className:`pi-settings-sidebar ${rA.trigger}`,"data-wide":e,type:`button`,"aria-label":m,disabled:o||s||!!c||u,onClick:()=>{p()},children:[(0,F.jsxs)(`span`,{className:rA.glyph,children:[(0,F.jsx)(_t,{size:e?16:18}),(0,F.jsx)(`span`,{className:rA.dot})]}),e&&(0,F.jsx)(`span`,{children:m})]})})}),(s||c)&&(0,F.jsx)(`span`,{className:rA.srOnly,role:`status`,children:m})]})}var sA={trigger:`_trigger_1s641_2`,item:`_item_1s641_3`};function cA({wide:e}){let t=l(),n=((e,n)=>f(t,e,n))(`帮助与文档`,`Help & documentation`),r=(0,P.useRef)(null),i=(0,P.useRef)(null),[a,o]=(0,P.useState)(!1),[s,c]=(0,P.useState)({top:0,left:0}),u=(e=!0)=>{o(!1),e&&r.current?.focus()};return(0,P.useLayoutEffect)(()=>{if(!a)return;let t=r.current.getBoundingClientRect(),{height:n,width:s}=i.current.getBoundingClientRect();c({top:Math.max(12,t.top-n-4),left:Math.max(12,Math.min(e?t.right-s:t.left,window.innerWidth-s-12))}),i.current?.querySelector(`a`)?.focus();let l=e=>{!i.current?.contains(e.target)&&!r.current?.contains(e.target)&&o(!1)},u=()=>{o(!1),r.current?.focus()};return document.addEventListener(`pointerdown`,l,!0),window.addEventListener(`resize`,u),()=>{document.removeEventListener(`pointerdown`,l,!0),window.removeEventListener(`resize`,u)}},[a,e]),(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(Xe,{label:n,disabled:a,children:(0,F.jsx)(`button`,{ref:r,type:`button`,className:`pi-settings-sidebar ${sA.trigger}`,"data-wide":e,"aria-label":n,"aria-haspopup":`menu`,"aria-expanded":a,onClick:()=>a?u():o(!0),onKeyDown:e=>{(e.key===`ArrowDown`||e.key===`ArrowUp`)&&(e.preventDefault(),o(!0))},children:(0,F.jsx)(kt,{size:e?16:18})})}),a&&(0,jt.createPortal)((0,F.jsx)(kp,{ref:i,role:`menu`,tabIndex:-1,"aria-label":n,className:kO.menu,style:s,onKeyDown:e=>{if(e.key===`Escape`)e.preventDefault(),e.stopPropagation(),u();else if(e.key===`Tab`)u();else if([`ArrowDown`,`ArrowUp`,`Home`,`End`].includes(e.key)){e.preventDefault();let t=[...i.current?.querySelectorAll(`a`)??[]],n=t.indexOf(document.activeElement);t[e.key===`Home`?0:e.key===`End`?t.length-1:e.key===`ArrowDown`?(n+1)%t.length:(n-1+t.length)%t.length]?.focus()}},children:Fk(t).map(e=>(0,F.jsx)(`a`,{role:`menuitem`,href:e.href,target:`_blank`,rel:`noreferrer`,className:`${kO.menuItem} ${kO.menuItemNeutral} ${sA.item}`,onClick:()=>u(!1),children:e.label},e.id))}),document.body)]})}var lA=e=>typeof e==`object`&&!!e&&!Array.isArray(e),uA=e=>typeof e==`string`,dA=e=>typeof e==`boolean`,fA=e=>typeof e==`number`&&Number.isFinite(e),pA=e=>t=>t===null||e(t),mA=e=>t=>Array.isArray(t)&&t.every(e),hA=(e,t,n)=>e[t]===void 0||n(e[t]),gA=(e,t)=>t.every(t=>uA(e[t])),_A=(e,t)=>t.every(t=>hA(e,t,uA));function vA(e){return lA(e)&&gA(e,[`id`,`timestamp`])&&[`user`,`assistant`,`tool`,`notice`].includes(e.role)&&mA(e=>lA(e)&&[`text`,`thinking`,`image`,`toolCall`].includes(e.kind)&&uA(e.text)&&_A(e,[`toolName`,`toolCallId`]))(e.blocks)&&_A(e,[`toolName`,`toolCallId`,`model`,`error`])&&hA(e,`isError`,dA)&&hA(e,`usage`,e=>lA(e)&&[`input`,`output`,`cacheRead`,`cacheWrite`,`totalTokens`,`cost`].every(t=>fA(e[t]))&&hA(e,`reasoning`,fA))}function yA(e){return lA(e)&&e.schemaVersion===1&&gA(e,[`sessionId`,`cwd`,`name`])&&pA(uA)(e.model)&&pA(uA)(e.thinkingLevel)&&mA(uA)(e.thinkingLevels)&&dA(e.idle)&&hA(e,`paused`,dA)&&hA(e,`hasPendingPrompts`,dA)&&hA(e,`promptQueue`,e=>lA(e)&&mA(uA)(e.steering)&&mA(uA)(e.followUp))&&hA(e,`queuedPrompts`,mA(e=>lA(e)&&gA(e,[`id`,`text`])&&Number.isSafeInteger(e.revision)&&e.revision>0&&[`queued`,`sending`].includes(e.status)&&hA(e,`error`,uA)&&mA(e=>lA(e)&&uA(e.name)&&dA(e.image))(e.attachments)))&&pA(e=>lA(e)&&pA(fA)(e.tokens)&&fA(e.contextWindow)&&pA(fA)(e.percent))(e.contextUsage)&&mA(vA)(e.messages)&&mA(e=>lA(e)&&gA(e,[`id`,`pluginId`,`kind`,`timestamp`])&&hA(e,`afterMessageId`,uA))(e.pluginEntries)&&hA(e,`interactions`,mA(e=>lA(e)&&gA(e,[`requestId`,`sessionId`,`pluginId`,`kind`])))&&hA(e,`streaming`,pA(vA))}function bA(e){return lA(e)&&pA(uA)(e.activeId)&&mA(e=>lA(e)&&gA(e,[`id`,`path`,`title`])&&hA(e,`available`,dA))(e.items)&&mA(e=>lA(e)&&gA(e,[`id`,`workspaceId`,`name`,`modified`])&&pA(uA)(e.path)&&hA(e,`idle`,dA))(e.sessions)}function xA(e){return lA(e)&&e.type===`error`&&uA(e.message)&&_A(e,[`errorCode`,`errorId`,`requestId`,`operationId`])&&hA(e,`errorReported`,dA)}function SA(e){if(!lA(e)||!uA(e.type))throw Error(`Invalid stream event`);switch(e.type){case`snapshot`:if(lA(e.session)&&e.session.schemaVersion!==1)throw Error(`Unsupported session schema`);if(yA(e.session))return{type:`snapshot`,session:e.session};throw Error(`Invalid session snapshot`);case`stream`:if(e.message===null||vA(e.message))return{type:`stream`,message:e.message};break;case`workspaces`:if(bA(e.value))return{type:`workspaces`,value:e.value};break;case`shutdown`:if(hA(e,`reconnect`,dA))return{type:`shutdown`,...e.reconnect===void 0?{}:{reconnect:e.reconnect}};break;case`plugins_changed`:return{type:`plugins_changed`};case`hosted_plugins_changed`:return{type:`hosted_plugins_changed`};case`plugin_state`:if(Array.isArray(e.disabled)&&e.disabled.every(e=>typeof e==`string`&&e.length<=200))return{type:`plugin_state`,disabled:e.disabled};break;case`error`:if(xA(e))return e;break;default:throw Error(`Unsupported stream event`)}throw Error(`Invalid stream event`)}var CA=ve();async function wA(e,n,r){return t(await s(e,{method:`POST`,headers:{Authorization:`Bearer ${CA}`,"Content-Type":`application/json`},body:JSON.stringify(n),signal:r}))}async function TA(e){return t(await s(e,{headers:{Authorization:`Bearer ${CA}`}}))}function EA(){let e=l(),[n,i]=(0,P.useState)(null),[a,o]=(0,P.useState)(null),[c,u]=(0,P.useState)(CA?`connecting`:`missing-token`),[d,f]=(0,P.useState)(``),[p,m]=(0,P.useState)([]),[h,g]=(0,P.useState)(`loading`),[_,v]=(0,P.useState)([]),[y,b]=(0,P.useState)({items:[],activeId:null,sessions:[]}),[x,S]=(0,P.useState)(null),[C,w]=(0,P.useState)([]),[T,E]=(0,P.useState)(0);return(0,P.useEffect)(()=>{if(!CA)return;let e=new AbortController,n,a=!0,c=!1;return(async()=>{for(;a;){let l,d,p=`stream_connect`;try{u(`connecting`);let n=await s(`/api/events`,{headers:{Authorization:`Bearer ${CA}`},cache:`no-store`,signal:e.signal}),{response:m}=n;if(d=n.correlation,m.ok||await t(n),!m.body)throw Error(m.status===401?r(`访问令牌无效,请在 Pi 中重新输入 /web。`,`Invalid access token. Run /web again in Pi.`):r(`连接 Pi 失败`,`Could not connect to Pi`));u(`connected`),he({connection:`connected`}),ye(`stream_connected`,{...d}),f(``),l=m.body.getReader();let h=new TextDecoder,g=``;for(;a;){p=`stream_read`;let{done:e,value:t}=await l.read();if(e)break;p=`stream_event`,g+=h.decode(t,{stream:!0});let n=g.indexOf(`
|
|
61
|
+
`)).text===te.text);(0,P.useEffect)(()=>{te&&(A||n&&n.sessionId!==te.sessionId)&&ne(null)},[te,A,n?.sessionId]);let re=te&&!A&&n?.sessionId===te.sessionId?{id:te.id,role:`user`,timestamp:te.timestamp,blocks:[{kind:`text`,text:te.text},...te.files.filter(e=>/\.(?:png|jpe?g|webp|gif)$/iu.test(e.name)||/^image\/(?:png|jpeg|webp|gif)$/.test(e.type)).map(()=>({kind:`image`,text:``}))],localFiles:te.files}:null,ie=pf(n,i,a,re!==null),j=mf(ff(n,i,a,re!==null),n?.sessionId,n?.activityId),ae=T.flatMap(e=>e.definition.workbench?.toolViews?.flatMap(e=>e.tools)??[]),oe=cp(n?.sessionId,[...n?.messages??[],...re?[re]:[],...i?[i]:[]],ae),M=n===null||oe.messages.length===0&&ie===null,se=async(e,t,r,i)=>{if(!n)return;if(i){await c(e,t,i);return}let a=`pending-${ge()}`;ne({id:a,sessionId:n.sessionId,text:e,files:r,knownIds:new Set(n.messages.map(e=>e.id)),timestamp:new Date().toISOString()});try{await c(e,t)}catch(e){throw ne(e=>e?.id===a?null:e),e}},ce=(0,P.useRef)(null),{scroll:le,content:ue,composer:de,onScroll:fe,onWheel:pe,showLatest:me,returnToLatest:N}=bO(n?.sessionId,!M&&D===`chat`,re?.id),[he,_e]=(0,P.useState)(0);(0,P.useLayoutEffect)(()=>{let e=ce.current;if(!e)return;let t=()=>_e(e.getBoundingClientRect().width);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let ve=n?.cwd.split(/[\\/]/).filter(Boolean).at(-1)||r(`Pi 工作区`,`Pi workspace`),ye=oe.messages,be=fp(ye),xe=lp(ye);return(0,F.jsxs)(`div`,{ref:ce,className:$t.root,"data-phase":M?`hero`:`active`,style:{"--piw-conversation-column-width":`${he}px`},children:[M&&(0,F.jsx)(`div`,{className:$t.heroTools,children:e}),n&&!M&&(0,F.jsxs)(`header`,{className:$t.header,children:[(0,F.jsxs)(`div`,{className:$t.titleRow,children:[(0,F.jsx)(`div`,{className:$t.titleCluster,children:(0,F.jsx)(`div`,{className:$t.crumbs,children:(0,F.jsx)(`span`,{className:`${$t.crumb} ${$t.crumbCurrent}`,children:n.name||r(`新会话`,`New chat`)})})}),(0,F.jsxs)(`div`,{className:$t.headerActions,children:[e,(0,F.jsx)($e,{state:a===`connected`?n.idle?`done`:`ongoing`:`error`}),(0,F.jsx)(`span`,{className:`pi-header-state`,children:a===`connected`?n.idle?r(`已连接`,`Connected`):r(`运行中`,`Running`):r(`已断开`,`Disconnected`)})]})]}),(0,F.jsxs)(`div`,{className:$t.tabs,role:`tablist`,"aria-label":r(`会话视图`,`Session views`),children:[(0,F.jsx)(`button`,{className:`${$t.tab} ${D===`chat`?$t.tabActive:``}`,role:`tab`,"aria-selected":D===`chat`,type:`button`,onClick:()=>O(`chat`),children:r(`对话`,`Chat`)}),(0,F.jsx)(`button`,{className:`${$t.tab} ${D===`trajectory`?$t.tabActive:``}`,role:`tab`,"aria-selected":D===`trajectory`,type:`button`,onClick:()=>O(`trajectory`),children:r(`轨迹`,`Trajectory`)})]})]}),(0,F.jsx)(`div`,{className:$t.body,children:(0,F.jsxs)(`div`,{ref:le,className:$t.scrollBody,"data-conversation-scroll":``,onScroll:fe,onWheel:pe,children:[!M&&(0,F.jsx)(`div`,{ref:ue,className:$t.viewArea,children:D===`chat`?(0,F.jsx)(`div`,{className:tn.root,children:(0,F.jsx)(`div`,{className:tn.scroll,children:(0,F.jsx)(`div`,{className:tn.column,children:(0,F.jsxs)(F.Fragment,{children:[xe.map(e=>(0,F.jsx)(SO,{turn:e,results:be,model:n?.model??null,loadImage:l,cwd:n?.cwd,renderPluginSlot:C,renderToolView:w,viewTools:ae,artifactTools:T.flatMap(e=>e.definition.artifactTools??[]),running:e===xe.at(-1)&&!n?.idle||e.messages.some(e=>e.id===`stream`),superseded:e!==xe.at(-1),onInspect:e=>{ee(e),O(`trajectory`)}},dp(e,ae))),ie&&(0,F.jsx)(df,{state:ie,elapsedSeconds:j})]})})})}):(0,F.jsx)(Dp,{messages:ye,inspectCallId:k})}),(0,F.jsx)(`div`,{ref:de,className:$t.composerSeat,"data-composer-seat":``,children:(0,F.jsxs)(`div`,{className:`${$t.composerStack} ${M?$t.composerHero:``}`,children:[M&&(0,F.jsx)(Qt,{t:e=>({"hero.headline":r(`有什么可以帮你?`,`How can I help?`),"hero.preview":`Pi`})[e]??e,renderSlot:(e,t,n)=>n?.fallback??null}),M&&(0,F.jsx)(`div`,{className:$t.heroWorkspaceRow,children:(0,F.jsxs)(`span`,{className:Zt.workspace,children:[(0,F.jsx)(xt,{size:16}),(0,F.jsx)(`span`,{className:Zt.workspaceLabel,children:ve})]})}),t,(0,F.jsx)(CO,{suspended:t!=null,hero:M,session:n,connection:a,onSend:se,onUpdateQueuedPrompt:S,onUpload:u,onDiscardAttachment:d,onStop:f,onResume:p,onCompact:m,onNewSession:h,commands:g,models:_,modelsStatus:v,onConfigureModels:y,onSetModel:b,onSetThinkingLevel:x,renderPluginSlot:C,plugins:T,onPluginAction:E}),oe.error&&(0,F.jsxs)(`div`,{className:`pi-error`,role:`alert`,children:[oe.error,(0,F.jsx)(`button`,{onClick:oe.retry,children:`Retry view cleanup`})]}),o&&(0,F.jsxs)(`div`,{className:`pi-error pi-error-dismissible`,role:`alert`,children:[(0,F.jsx)(`span`,{children:o}),(0,F.jsx)(`button`,{type:`button`,className:`pi-error-dismiss`,"aria-label":r(`关闭错误`,`Dismiss error`),onClick:s,children:`×`})]})]})}),me&&(0,F.jsx)(`div`,{className:tn.toBottomSlot,children:(0,F.jsx)(`button`,{className:tn.toBottom,type:`button`,"aria-label":r(`回到最新`,`Back to latest`),title:r(`回到最新并继续跟随`,`Back to latest and resume following`),onClick:N,children:(0,F.jsx)(`svg`,{viewBox:`0 0 16 16`,width:`16`,height:`16`,"aria-hidden":`true`,children:(0,F.jsx)(`path`,{d:`M8 2v12m-5-5 5 5 5-5`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`})})})})]})})]})}var TO={button:`_button_cfgyt_4`,md:`_md_cfgyt_24`,sm:`_sm_cfgyt_30`,primary:`_primary_cfgyt_38`,ghost:`_ghost_cfgyt_47`,outline:`_outline_cfgyt_56`,toolbar:`_toolbar_cfgyt_65`,icon:`_icon_cfgyt_73`};function EO({variant:e=`ghost`,size:t=`md`,icon:r,className:i,children:a,...o}){return(0,F.jsxs)(`button`,{type:`button`,className:n(TO.button,TO[e],TO[t],i),...o,children:[r!=null&&(0,F.jsx)(`span`,{className:TO.icon,children:r}),a]})}var DO={root:`_root_w1urq_2`,mask:`_mask_w1urq_14`,dialog:`_dialog_w1urq_22`,content:`_content_w1urq_37`,header:`_header_w1urq_45`,title:`_title_w1urq_53`,close:`_close_w1urq_61`,description:`_description_w1urq_80`,body:`_body_w1urq_89`,footer:`_footer_w1urq_97`};function OO({open:e,onClose:t,title:r,closeLabel:i,description:a,children:o,footer:s,className:c,contentClassName:l,headless:u=!1}){let d=(0,P.useRef)(null);return ze(d,e,t),e?(0,jt.createPortal)((0,F.jsx)(Fe.Provider,{value:d,children:(0,F.jsxs)(`div`,{className:DO.root,role:`presentation`,children:[(0,F.jsx)(`div`,{className:DO.mask,"aria-hidden":`true`,onClick:t}),(0,F.jsx)(`div`,{ref:d,tabIndex:-1,className:n(DO.dialog,c),role:`dialog`,"aria-modal":`true`,"aria-label":r,children:u?o:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`div`,{className:n(DO.content,l),children:[(0,F.jsxs)(`div`,{className:DO.header,children:[(0,F.jsx)(`h2`,{className:DO.title,children:r}),(0,F.jsx)(`button`,{type:`button`,className:DO.close,"aria-label":i,onClick:t,children:(0,F.jsx)(ut,{size:14})})]}),a!==void 0&&a!==``&&(0,F.jsx)(`p`,{className:DO.description,children:a}),o!==void 0&&(0,F.jsx)(`div`,{className:DO.body,children:o})]}),s!==void 0&&(0,F.jsx)(`div`,{className:DO.footer,children:s})]})})]})}),document.body):null}var kO={group:`_group_7dgiw_4`,workspaceLine:`_workspaceLine_7dgiw_5`,workspaceButton:`_workspaceButton_7dgiw_7`,workspaceTitle:`_workspaceTitle_7dgiw_8`,folder:`_folder_7dgiw_9`,folderActive:`_folderActive_7dgiw_10`,unavailable:`_unavailable_7dgiw_11`,chevron:`_chevron_7dgiw_12`,chevronOpen:`_chevronOpen_7dgiw_13`,rowActions:`_rowActions_7dgiw_16`,rowAction:`_rowAction_7dgiw_16`,sessionButton:`_sessionButton_7dgiw_23`,sessionLine:`_sessionLine_7dgiw_24`,sessionTime:`_sessionTime_7dgiw_27`,untitled:`_untitled_7dgiw_31`,renameInput:`_renameInput_7dgiw_32`,error:`_error_7dgiw_38`,menu:`_menu_7dgiw_39`,menuItem:`_menuItem_7dgiw_40`,menuItemNeutral:`_menuItemNeutral_7dgiw_42`,menuHint:`_menuHint_7dgiw_44`};function AO({title:e,active:t,disabled:n,open:i,onOpenChange:a,onRemove:o}){return(0,F.jsx)(MO,{label:r(`${e} 的工作区操作`,`Workspace actions for ${e}`),title:r(`工作区操作`,`Workspace actions`),disabled:n,open:i,onOpenChange:a,items:[{label:r(`从列表移除工作区`,`Remove workspace from list`),icon:(0,F.jsx)(ht,{}),destructive:!0,disabled:t,onSelect:o}],hint:t?r(`请先切换到其他工作区再移除`,`Switch to another workspace before removing`):r(`不删除目录、文件或会话历史`,`Keeps directories, files and session history`)})}function jO({title:e,disabled:t,open:n,onOpenChange:i,onRename:a,onDelete:o}){return(0,F.jsx)(MO,{label:r(`${e} 的会话操作`,`Chat actions for ${e}`),title:r(`会话操作`,`Chat actions`),disabled:t,open:n,onOpenChange:i,items:[{label:r(`重命名`,`Rename`),icon:(0,F.jsx)(pt,{}),onSelect:a},{label:r(`删除会话`,`Delete chat`),icon:(0,F.jsx)(ht,{}),destructive:!0,onSelect:o}]})}function MO({label:e,title:t,disabled:n,open:r,onOpenChange:i,items:a,hint:o}){let s=(0,P.useRef)(null),c=(0,P.useRef)(null),[l,u]=(0,P.useState)({top:0,left:0}),d=(0,P.useRef)({onOpenChange:i});d.current={onOpenChange:i};let f=(e=!0)=>{i(!1),e&&s.current?.focus()};return(0,P.useLayoutEffect)(()=>{if(!r)return;let e=s.current.getBoundingClientRect(),t=c.current.getBoundingClientRect().height;u({top:Math.max(12,Math.min(e.bottom+4,window.innerHeight-t-12)),left:Math.max(12,Math.min(e.right-220,window.innerWidth-232))}),(c.current?.querySelector(`button:not(:disabled)`)??c.current)?.focus();let n=e=>{!c.current?.contains(e.target)&&!s.current?.contains(e.target)&&d.current.onOpenChange(!1)},i=()=>{d.current.onOpenChange(!1),s.current?.focus()};return document.addEventListener(`pointerdown`,n,!0),window.addEventListener(`resize`,i),window.addEventListener(`scroll`,i,!0),()=>{document.removeEventListener(`pointerdown`,n,!0),window.removeEventListener(`resize`,i),window.removeEventListener(`scroll`,i,!0)}},[r]),(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`button`,{ref:s,type:`button`,className:kO.rowAction,disabled:n,"aria-label":e,title:t,"aria-haspopup":`menu`,"aria-expanded":r,onClick:()=>r?f():i(!0),onKeyDown:e=>{(e.key===`ArrowDown`||e.key===`ArrowUp`)&&(e.preventDefault(),i(!0))},children:(0,F.jsx)(at,{})}),r&&(0,jt.createPortal)((0,F.jsxs)(kp,{ref:c,role:`menu`,tabIndex:-1,"aria-label":e,className:kO.menu,style:l,onKeyDown:e=>{if(e.key===`Escape`)e.preventDefault(),e.stopPropagation(),f();else if(e.key===`Tab`)f();else if([`ArrowDown`,`ArrowUp`,`Home`,`End`].includes(e.key)){e.preventDefault();let t=[...c.current?.querySelectorAll(`button:not(:disabled)`)??[]],n=t.indexOf(document.activeElement);t[e.key===`Home`?0:e.key===`End`?t.length-1:e.key===`ArrowDown`?(n+1)%t.length:(n-1+t.length)%t.length]?.focus()}},children:[a.map(e=>(0,F.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`${kO.menuItem} ${e.destructive?``:kO.menuItemNeutral}`,disabled:n||e.disabled,onClick:()=>{f(),e.onSelect()},children:[e.icon,e.label]},e.label)),o&&(0,F.jsx)(`p`,{className:kO.menuHint,children:o})]}),document.body)]})}function NO(e,t,n){let r=Date.parse(e);if(!Number.isFinite(r))return``;let i=Math.max(0,Math.floor((t-r)/6e4));if(i<1)return n===`zh`?`刚刚`:`now`;let[a,o,s]=[[525600,`年`,`yr`],[43200,`个月`,`mo`],[10080,`周`,`wk`],[1440,`天`,`d`],[60,`小时`,`h`],[1,`分钟`,`min`]].find(([e])=>i>=e);return`${Math.floor(i/a)}${n===`zh`?o:s}`}var PO={dialog:`_dialog_s0tgk_1`,editorScope:`_editorScope_s0tgk_21`,header:`_header_s0tgk_26`,title:`_title_s0tgk_35`,crumbBar:`_crumbBar_s0tgk_51`,crumbEditZone:`_crumbEditZone_s0tgk_65`,pathInput:`_pathInput_s0tgk_67`,millerRow:`_millerRow_s0tgk_78`,crumbTrail:`_crumbTrail_s0tgk_91`,crumbSeat:`_crumbSeat_s0tgk_101`,crumb:`_crumb_s0tgk_51`,crumbChevron:`_crumbChevron_s0tgk_128`,crumbEditGlyph:`_crumbEditGlyph_s0tgk_151`,content:`_content_s0tgk_187`,column:`_column_s0tgk_186`,divider:`_divider_s0tgk_216`,rowSeat:`_rowSeat_s0tgk_222`,row:`_row_s0tgk_222`,rowSelected:`_rowSelected_s0tgk_247`,rowIcon:`_rowIcon_s0tgk_252`,rowIconSelected:`_rowIconSelected_s0tgk_257`,rowName:`_rowName_s0tgk_262`,rowChevron:`_rowChevron_s0tgk_274`,status:`_status_s0tgk_279`,error:`_error_s0tgk_280`,loadingFloat:`_loadingFloat_s0tgk_192`,footerBar:`_footerBar_s0tgk_317`,showHiddenToggle:`_showHiddenToggle_s0tgk_333`,showHiddenToggleActive:`_showHiddenToggleActive_s0tgk_357`,footerGap:`_footerGap_s0tgk_361`,footerAction:`_footerAction_s0tgk_365`,createDialog:`_createDialog_s0tgk_370`,createBody:`_createBody_s0tgk_376`,createTitle:`_createTitle_s0tgk_383`,createIn:`_createIn_s0tgk_391`,createInput:`_createInput_s0tgk_398`,createActions:`_createActions_s0tgk_416`};function FO(e){if(typeof e==`object`&&e&&`rpcError`in e){let t=e.rpcError;if(typeof t==`object`&&t&&`message`in t&&typeof t.message==`string`)return t.message}return e instanceof Error?e.message:String(e)}var IO=300,LO=200,RO=250;function zO(e,t){let n=e.crumbs.findIndex(t=>t.path===e.home);if(n===-1)return e.crumbs;let r=e.crumbs.slice(n+1);return[{name:t,path:e.home,hidden:!1},...r]}function BO(e){return e.home.includes(`\\`)?`\\`:`/`}function VO(e){let t=BO(e);return e.path.endsWith(t)?e.path:`${e.path}${t}`}function HO(e,t){let n=BO(e)===`\\`?Math.max(t.lastIndexOf(`\\`),t.lastIndexOf(`/`)):t.lastIndexOf(`/`);return n===-1?null:t.slice(0,n+1)}function UO(e,t,n){let r=HO(e,t);return r===null?{directory:null,tail:null}:{directory:r,tail:r===VO(e)||n!==null&&n.directory===r&&n.landed===e.path?t.slice(r.length):null}}function WO(e,t,n,r){let i=r===null?``:r.toLowerCase(),a=e=>n||!e.hidden||i.startsWith(`.`),o=e=>a(e)&&e.name.toLowerCase().startsWith(i),s=i!==``&&e.some(o);return e.filter(e=>e.path===t?!0:s?o(e):n||!e.hidden)}function GO({entries:e,selectedPath:t,busy:r,onPick:i,showHidden:a,filterPrefix:o,pathEditing:s}){let c=WO(e,t,a,o);return(0,F.jsx)(`div`,{className:PO.column,role:`list`,children:c.map(e=>{let a=e.path===t;return(0,F.jsx)(`span`,{role:`listitem`,className:PO.rowSeat,children:(0,F.jsxs)(`button`,{type:`button`,"aria-current":a||void 0,className:n(PO.row,a&&PO.rowSelected),disabled:r,onMouseDown:s?e=>{e.preventDefault()}:void 0,onClick:()=>{i(e)},children:[a?(0,F.jsx)(xt,{size:16,className:PO.rowIconSelected}):(0,F.jsx)(St,{size:16,className:PO.rowIcon}),(0,F.jsx)(`span`,{className:PO.rowName,children:e.name}),(0,F.jsx)(lt,{size:12,className:PO.rowChevron})]})},e.path)})})}function KO({open:e,listDirectory:t,createDirectory:r,onOpen:i,onClose:a,busy:o,t:s}){let[c,l]=(0,P.useState)(null),[u,d]=(0,P.useState)(null),[f,p]=(0,P.useState)(null),[m,h]=(0,P.useState)(!1),[g,_]=(0,P.useState)(!1),[v,y]=(0,P.useState)(0),[b,x]=(0,P.useState)(null),[S,C]=(0,P.useState)(null),[w,T]=(0,P.useState)(!1),[E,D]=(0,P.useState)(null),[O,k]=(0,P.useState)(!1),[ee,te]=(0,P.useState)(null),ne=(0,P.useRef)(0),A=(0,P.useRef)(null),re=(0,P.useRef)(0),ie=(0,P.useRef)(null),j=(0,P.useRef)(!1);(0,P.useEffect)(()=>()=>{ne.current+=1,re.current+=1,A.current?.abort()},[]);let ae={onCompositionStart:()=>{j.current=!0},onCompositionEnd:()=>{j.current=!1}},oe=(0,P.useCallback)(()=>(A.current?.abort(),A.current=null,++ne.current),[]),M=(0,P.useCallback)(()=>{_(!1),y(e=>e+1)},[]),se=(0,P.useCallback)(e=>{let n=oe(),r=new AbortController;return A.current=r,M(),{seq:n,scan:t(e,r.signal)}},[oe,M,t]),ce=(0,P.useCallback)(e=>{let n=new AbortController;return A.current=n,M(),t(e,n.signal)},[M,t]),le=(0,P.useRef)(!1),ue=(0,P.useRef)({parent:null,child:null});(0,P.useEffect)(()=>{ue.current={parent:c,child:f}},[c,f]);let de=(0,P.useRef)(null),fe=(0,P.useRef)(!1),pe=(0,P.useCallback)((e,t)=>{let{seq:n,scan:r}=se(e);h(!0),t.announce&&x(null);let i=()=>{h(!1),t.closeEditor?C(null):(x(null),fe.current=!0)};r.then(r=>{if(n!==ne.current)return;!t.closeEditor&&e!==void 0&&(de.current={directory:e,landed:r.path});let a=!1,o=()=>{a||n!==ne.current||(a=!0,l(r),d(null),p(null),i())};if(zO(r,``).length<2){o();return}let s=r.crumbs.at(-2);s===void 0?o():(ce(s.path).then(e=>{if(n!==ne.current)return;let t=BO(e),s=e=>t===`\\`?e.toLowerCase():e,c=e.entries.find(e=>s(e.path)===s(r.path));c===void 0?o():(a=!0,l(e),d(c),p(r),i())},()=>{o()}),t.closeEditor&&window.setTimeout(o,LO))},e=>{n===ne.current&&(h(!1),t.announce&&x(FO(e)))})},[se,ce]),me=(0,P.useCallback)(e=>{pe(e,{closeEditor:!0,announce:!0})},[pe]),N=(0,P.useRef)(!1),he=(0,P.useRef)(!1),ge=(0,P.useRef)(null),_e=(0,P.useRef)(null),ve=(0,P.useCallback)(e=>{let{seq:t,scan:n}=se(e.path);S!==null&&(N.current=!0),C(null),d(e),p(null),h(!0),x(null),n.then(e=>{t===ne.current&&(p(e),h(!1))},e=>{t===ne.current&&(h(!1),x(FO(e)),d(null),he.current=!0)})},[se,S]),ye=(0,P.useCallback)(e=>{pe(e,{closeEditor:!1,announce:!1})},[pe]),be=(0,P.useCallback)(()=>{oe(),h(!1),C(null),x(null),f===null&&d(null),c===null&&me()},[oe,f,c,me]),xe=(0,P.useCallback)(e=>{f!==null&&(l(f),ve(e))},[f,ve]);(0,P.useEffect)(()=>{re.current+=1,e?(l(null),d(null),p(null),k(!1),T(!1),me()):(oe(),h(!1),x(null),C(null),D(null),te(null),N.current=!1,he.current=!1)},[e,me,oe]);let Se=u?.path??c?.path??null,Ce=u?.name??(c===null?``:zO(c,s(`browser.home`)).at(-1)?.name??c.path),we=()=>{if(Se===null||E===null||O)return;let e=E;if(e.trim()===``)return;k(!0),te(null);let t=re.current;r(Se,e).then(n=>{if(t!==re.current)return;k(!1),D(null);let{seq:r,scan:i}=se(Se);h(!0),x(null),i.then(t=>{r===ne.current&&(l(t),h(!1),ve({name:e,path:n,hidden:!1}))},e=>{r===ne.current&&(h(!1),x(FO(e)))})},e=>{t===re.current&&(k(!1),te(FO(e)))})};(0,P.useEffect)(()=>{if(!m){_(!1);return}let e=window.setTimeout(()=>{_(!0)},IO);return()=>{window.clearTimeout(e)}},[m,v]),(0,P.useEffect)(()=>{if(S===null)return;let e=window.setTimeout(()=>{if(le.current)return;let e=ue.current.child??ue.current.parent;if(e===null)return;let{directory:t,tail:n}=UO(e,S,de.current);t!==null&&n===null&&ye(t)},RO);return()=>{window.clearTimeout(e)}},[S,ye]);let Te=f??c,Ee=Te===null||S===null?null:UO(Te,S,de.current).tail,De=Te===null?[]:zO(Te,s(`browser.home`)),Oe=De.at(-1)?.path;(0,P.useEffect)(()=>{let e=ie.current;e!==null&&(e.scrollLeft=e.scrollWidth)},[Oe]);let ke=(0,P.useRef)(null),Ae=f?.path;if((0,P.useEffect)(()=>{let e=ke.current;e!==null&&Ae!==void 0&&(e.scrollLeft=e.scrollWidth)},[Ae]),(0,P.useEffect)(()=>{if(fe.current&&(fe.current=!1,document.activeElement===document.body&&ge.current?.focus()),S===null){if(N.current){N.current=!1,he.current=!1;let e=ke.current;if(e===null)return;let t=e.querySelector(`button[aria-current="true"]`);if(t===null)return;t.focus()}else if(he.current){if(he.current=!1,document.activeElement!==document.body)return;let e=_e.current;if(e===null)return;e.focus()}}}),!e)return null;let je=u!==null,Me=o||E!==null,Ne=S!==null;return(0,F.jsxs)(OO,{open:e,onClose:()=>{E===null&&!o&&a()},title:s(`browser.title`),className:n(PO.dialog),headless:!0,children:[(0,F.jsxs)(`div`,{className:PO.editorScope,onKeyDown:e=>{e.key===`Escape`&&S!==null&&(e.stopPropagation(),he.current=document.activeElement===ge.current,be())},onBlur:e=>{if(S===null||!document.hasFocus())return;let t=e.currentTarget.closest(`[role="dialog"]`);t!==null&&(e.relatedTarget instanceof Node&&t.contains(e.relatedTarget)||(he.current=!1,be()))},children:[(0,F.jsxs)(`div`,{className:PO.header,children:[(0,F.jsx)(`h2`,{className:PO.title,children:s(`browser.title`)}),(0,F.jsx)(`div`,{className:PO.crumbBar,children:S===null?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`span`,{className:PO.crumbTrail,role:`navigation`,ref:ie,children:De.map((e,t)=>(0,F.jsxs)(`span`,{className:PO.crumbSeat,children:[t>0&&(0,F.jsx)(lt,{size:12,className:PO.crumbChevron}),(0,F.jsx)(`button`,{type:`button`,className:PO.crumb,disabled:Me,onClick:()=>{me(e.path)},children:e.name})]},e.path))}),(0,F.jsx)(`button`,{type:`button`,className:PO.crumbEditZone,"aria-label":s(`browser.editPath`),title:s(`browser.editPath`),disabled:Me,ref:_e,onClick:()=>{if(oe(),h(!1),le.current=!1,c===null){C(``);return}let e=u?.path??c.path,t=BO(c);C(e.endsWith(t)?e:`${e}${t}`)},children:(0,F.jsx)(pt,{size:14,className:PO.crumbEditGlyph})})]}):(0,F.jsx)(`input`,{className:PO.pathInput,value:S,"aria-label":s(`browser.editPath`),autoFocus:!0,ref:ge,disabled:Me,onChange:e=>{oe(),h(!1),le.current=!1,C(e.target.value)},...ae,onKeyDown:e=>{e.key===`Enter`&&!j.current&&(e.preventDefault(),S.trim()!==``&&(he.current=!0,le.current=!0,me(S)))}})})]}),(0,F.jsxs)(`div`,{className:PO.content,children:[(0,F.jsxs)(`div`,{className:PO.millerRow,ref:ke,children:[c!==null&&(0,F.jsx)(GO,{entries:c.entries,selectedPath:u?.path??null,busy:Me,onPick:ve,showHidden:w,filterPrefix:f===null?Ee:null,pathEditing:Ne}),je&&(0,F.jsx)(`span`,{className:PO.divider}),je&&f!==null&&(0,F.jsx)(GO,{entries:f.entries,selectedPath:null,busy:Me,onPick:xe,showHidden:w,filterPrefix:Ee,pathEditing:Ne})]}),m&&g&&(0,F.jsx)(`div`,{className:n(PO.status,PO.loadingFloat),role:`status`,children:s(`browser.loading`)}),(c?.truncated===!0||f?.truncated===!0)&&(0,F.jsx)(`div`,{className:PO.status,role:`status`,children:s(`browser.truncated`)}),b!==null&&(0,F.jsx)(`div`,{className:PO.error,role:`alert`,children:b})]}),(0,F.jsxs)(`div`,{className:PO.footerBar,children:[(0,F.jsx)(EO,{variant:`outline`,icon:(0,F.jsx)(ot,{size:14}),disabled:c===null||m||Me||Ne,onClick:()=>{D(``),te(null)},children:s(`browser.newFolder`)}),(0,F.jsxs)(`button`,{type:`button`,className:n(PO.showHiddenToggle,w&&PO.showHiddenToggleActive),"aria-pressed":w,disabled:Me,onMouseDown:Ne?e=>{e.preventDefault()}:void 0,onClick:()=>{T(e=>!e)},children:[s(`browser.showHidden`),w&&(0,F.jsx)(st,{size:14})]}),(0,F.jsx)(`span`,{className:PO.footerGap}),(0,F.jsx)(EO,{variant:`outline`,className:n(PO.footerAction),disabled:Me,onClick:a,children:s(`browser.cancel`)}),(0,F.jsx)(EO,{variant:`primary`,className:n(PO.footerAction),disabled:Se===null||m||Me||Ne,onClick:()=>{Se!==null&&i(Se)},children:s(`browser.open`)})]})]}),(0,F.jsx)(OO,{open:E!==null,onClose:()=>{O||D(null)},title:s(`browser.newFolder`),className:n(PO.createDialog),headless:!0,children:(0,F.jsxs)(`div`,{className:PO.createBody,children:[(0,F.jsx)(`h3`,{className:PO.createTitle,children:s(`browser.newFolder`)}),(0,F.jsx)(`p`,{className:PO.createIn,children:s(`browser.createIn`,{name:Ce})}),(0,F.jsx)(`input`,{className:PO.createInput,value:E??``,"aria-label":s(`browser.folderName`),placeholder:s(`browser.untitledFolder`),autoFocus:!0,disabled:O,onChange:e=>{D(e.target.value)},...ae,onKeyDown:e=>{e.key===`Enter`&&!j.current&&(e.preventDefault(),we()),e.key===`Escape`&&(e.stopPropagation(),O||D(null))}}),ee!==null&&(0,F.jsx)(`div`,{className:PO.error,role:`alert`,children:ee}),(0,F.jsxs)(`div`,{className:PO.createActions,children:[(0,F.jsx)(EO,{variant:`outline`,disabled:O,onClick:()=>{D(null)},children:s(`browser.cancel`)}),(0,F.jsx)(EO,{variant:`primary`,disabled:O||E===null||E.trim()===``,onClick:we,children:s(`browser.create`)})]})]})})]})}var qO={root:`_root_nvze1_1`,rail:`_rail_nvze1_13`,iconButton:`_iconButton_nvze1_17`,searchButton:`_searchButton_nvze1_33`,clearButton:`_clearButton_nvze1_34`,sectionHeader:`_sectionHeader_nvze1_45`,sectionLabel:`_sectionLabel_nvze1_65`,sectionLabelHidden:`_sectionLabelHidden_nvze1_82`,searchSlot:`_searchSlot_nvze1_91`,searchSlotExpanded:`_searchSlotExpanded_nvze1_105`,headerActions:`_headerActions_nvze1_110`,headerActionsHidden:`_headerActionsHidden_nvze1_126`,search:`_search_nvze1_33`,searchExpanded:`_searchExpanded_nvze1_160`,searchInput:`_searchInput_nvze1_199`,listArea:`_listArea_nvze1_285`,treeBody:`_treeBody_nvze1_305`,fade:`_fade_nvze1_315`,wide:`_wide_nvze1_326`,"wide-in":`_wide-in_nvze1_1`,list:`_list_nvze1_285`,flatList:`_flatList_nvze1_356`,searchTree:`_searchTree_nvze1_357`,groupSection:`_groupSection_nvze1_358`,searchStatus:`_searchStatus_nvze1_362`,searchWarning:`_searchWarning_nvze1_363`,listTopDropIndicator:`_listTopDropIndicator_nvze1_383`,workspaceDropBefore:`_workspaceDropBefore_nvze1_384`,workspaceDropAfter:`_workspaceDropAfter_nvze1_385`,listTopDropActive:`_listTopDropActive_nvze1_419`,sessionOverflowButton:`_sessionOverflowButton_nvze1_431`,empty:`_empty_nvze1_453`,renameInput:`_renameInput_nvze1_460`,renameError:`_renameError_nvze1_479`,deleteAction:`_deleteAction_nvze1_486`,deleteStatus:`_deleteStatus_nvze1_490`},JO={projectRow:`_projectRow_mhb10_1`,sessionRow:`_sessionRow_mhb10_2`,selected:`_selected_mhb10_18`,searchResultRow:`_searchResultRow_mhb10_22`,searchResultHeading:`_searchResultHeading_mhb10_46`,searchResultTitle:`_searchResultTitle_mhb10_52`,searchResultMeta:`_searchResultMeta_mhb10_63`,searchResultWorkspace:`_searchResultWorkspace_mhb10_71`,searchResultSnippet:`_searchResultSnippet_mhb10_72`,rowActions:`_rowActions_mhb10_99`,"row-in":`_row-in_mhb10_1`,title:`_title_mhb10_112`,flatSessionRowWithoutStatus:`_flatSessionRowWithoutStatus_mhb10_116`,slot:`_slot_mhb10_124`,visuallyHidden:`_visuallyHidden_mhb10_134`,folderActive:`_folderActive_mhb10_143`,chevron:`_chevron_mhb10_149`,folder:`_folder_mhb10_143`,arrow:`_arrow_mhb10_154`,arrowOpen:`_arrowOpen_mhb10_158`,projectText:`_projectText_mhb10_162`,renameInput:`_renameInput_mhb10_179`,meta:`_meta_mhb10_195`,time:`_time_mhb10_204`,scheduleIndicator:`_scheduleIndicator_mhb10_211`,searchScheduleIndicator:`_searchScheduleIndicator_mhb10_222`,dot:`_dot_mhb10_227`,menuOpen:`_menuOpen_mhb10_242`,dropBefore:`_dropBefore_mhb10_261`,dropAfter:`_dropAfter_mhb10_262`,hoverContent:`_hoverContent_mhb10_302`,hoverTitle:`_hoverTitle_mhb10_308`,hoverPath:`_hoverPath_mhb10_315`,hoverTime:`_hoverTime_mhb10_322`,hoverStatus:`_hoverStatus_mhb10_328`,iconButton:`_iconButton_mhb10_337`},YO=(e,t)=>({"browser.title":r(`选择工作区目录`,`Select workspace directory`),"browser.home":r(`主目录`,`Home`),"browser.newFolder":r(`新建文件夹`,`New folder`),"browser.folderName":r(`文件夹名称`,`Folder name`),"browser.createIn":r(`在"{name}"中新建文件夹`,`Create folder in "{name}"`),"browser.untitledFolder":r(`未命名文件夹`,`Untitled folder`),"browser.create":r(`创建`,`Create`),"browser.cancel":r(`取消`,`Cancel`),"browser.open":r(`打开`,`Open`),"browser.editPath":r(`编辑路径`,`Edit path`),"browser.loading":r(`加载中…`,`Loading…`),"browser.truncated":r(`文件夹过多,仅显示开头部分。`,`Too many folders; only the first few are shown.`),"browser.showHidden":r(`显示隐藏文件`,`Show hidden files`)}[e]??e).replace(/\{(\w+)\}/g,(e,n)=>t?.[n]??``);function XO({wide:e,navigationBusy:t=!1,connected:n=!0,expandSidebar:i,session:a,workspaces:o,onAdd:s,directoryPickerKind:c,pickDirectory:u,listDirectory:d,createDirectory:f,onRemove:p,onSelectSession:m,onNewSession:h,onRenameSession:g,onDeleteSession:_}){let v=l(),[y,b]=(0,P.useState)(Date.now),[x,S]=(0,P.useState)(null),[C,w]=(0,P.useState)(null),[T,E]=(0,P.useState)(null),[D,O]=(0,P.useState)(``),[k,ee]=(0,P.useState)(null),te=(0,P.useRef)(null);(0,P.useEffect)(()=>{if(!T)return;let e=requestAnimationFrame(()=>{te.current?.focus(),te.current?.select()});return()=>cancelAnimationFrame(e)},[T]),(0,P.useEffect)(()=>{if(!e){S(null),w(null);return}b(Date.now());let t=window.setInterval(()=>b(Date.now()),6e4);return()=>window.clearInterval(t)},[e]);let[ne,A]=(0,P.useState)(!1),[re,ie]=(0,P.useState)(!1),j=re||t,ae=j||!n,oe=(0,P.useId)(),M=(0,P.useRef)(null),[se,ce]=(0,P.useState)(null),[le,ue]=(0,P.useState)(``),[de,fe]=(0,P.useState)(``),[pe,me]=(0,P.useState)(!1),[N,he]=(0,P.useState)(``);(0,P.useEffect)(()=>{he(``)},[a?.sessionId]);let[ge,_e]=(0,P.useState)(new Set);(0,P.useEffect)(()=>{o.activeId&&_e(e=>e.has(o.activeId)?e:new Set([...e,o.activeId]))},[o.activeId,a?.sessionId]),(0,P.useEffect)(()=>{M.current?.querySelector(`[aria-current="page"]`)?.scrollIntoView({block:`nearest`})},[e,a?.sessionId,ge]);let ve=(0,P.useRef)(null),ye=(0,P.useRef)(null),be=N.trim().toLocaleLowerCase(),xe=()=>{he(``),me(!1),ve.current?.focus()},Se=o.items.filter(e=>!be||e.title.toLocaleLowerCase().includes(be)||e.path.toLocaleLowerCase().includes(be)||o.sessions.some(t=>t.workspaceId===e.id&&t.name.toLocaleLowerCase().includes(be))),Ce=async e=>{if(!ae){ie(!0),ue(``);try{await e()}catch(e){ue(e instanceof Error?e.message:r(`操作失败`,`Operation failed`))}finally{ie(!1)}}},we=async e=>{ie(!0);try{await s(e,!1),A(!1)}catch(e){A(!1),fe(e instanceof Error?e.message:String(e))}finally{ie(!1)}},Te=async()=>{if(c!==null){if(e||i(),ue(``),c===`browse`)A(!0);else{ie(!0);try{let e=await u();e!==null&&await we(e)}catch(e){fe(e instanceof Error?e.message:String(e))}finally{ie(!1)}}}};return(0,F.jsxs)(`div`,{ref:M,"aria-busy":j,className:`${qO.root} ${e?``:qO.rail}`,children:[(0,F.jsxs)(`div`,{className:qO.sectionHeader,children:[e&&(0,F.jsx)(`span`,{className:`${qO.sectionLabel} ${qO.wide} ${pe?qO.sectionLabelHidden:``}`,children:r(`工作区`,`Workspaces`)}),e&&(0,F.jsx)(`div`,{className:`${qO.searchSlot} ${pe?qO.searchSlotExpanded:``}`,children:(0,F.jsxs)(`div`,{className:`${qO.search} ${pe?qO.searchExpanded:``}`,onClick:()=>{me(!0),ye.current?.focus()},children:[(0,F.jsx)(`button`,{ref:ve,type:`button`,className:qO.searchButton,"aria-label":r(`搜索工作区和会话`,`Search workspaces and sessions`),"aria-expanded":pe,onClick:()=>{me(!0),ye.current?.focus()},children:(0,F.jsx)(tt,{size:pe?11:14})}),(0,F.jsx)(`input`,{ref:ye,className:qO.searchInput,type:`search`,"aria-label":r(`按名称或工作区路径搜索`,`Search by name or workspace path`),placeholder:r(`按名称或工作区路径搜索`,`Search by name or workspace path`),maxLength:120,value:N,tabIndex:pe?0:-1,onChange:e=>he(e.target.value),onKeyDown:e=>{e.key===`Escape`&&(e.stopPropagation(),xe())}}),pe&&(0,F.jsx)(`button`,{type:`button`,className:qO.clearButton,"aria-label":r(`关闭搜索`,`Close search`),onClick:e=>{e.stopPropagation(),xe()},children:(0,F.jsx)(dt,{})})]})}),(0,F.jsx)(`div`,{className:`${qO.headerActions} ${e&&pe?qO.headerActionsHidden:``}`,children:(0,F.jsx)(`button`,{type:`button`,className:qO.iconButton,"aria-label":r(`添加工作区`,`Add workspace`),title:r(`添加工作区`,`Add workspace`),disabled:ae||c===null,onClick:()=>{Te()},children:(0,F.jsx)(bt,{size:e?16:18})})})]}),e&&(0,F.jsx)(`div`,{className:qO.listArea,children:(0,F.jsx)(`div`,{className:qO.treeBody,children:(0,F.jsxs)(`div`,{className:qO.list,role:`list`,"aria-label":r(`工作区`,`Workspaces`),children:[Se.map(e=>{let t=e.id===o.activeId,n=e.available===!1,i=ge.has(e.id)||!!be;return(0,F.jsxs)(`div`,{className:kO.group,role:`listitem`,children:[(0,F.jsxs)(`div`,{className:kO.workspaceLine,"data-menu-open":x===e.id||void 0,children:[(0,F.jsxs)(`button`,{type:`button`,className:`${JO.projectRow} ${kO.workspaceButton}`,"aria-expanded":i,"aria-controls":`${oe}-${e.id}`,title:e.path,disabled:j,onContextMenu:t=>{ae||(t.preventDefault(),t.stopPropagation(),w(null),S(e.id))},onClick:()=>_e(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n}),children:[(0,F.jsxs)(`span`,{className:JO.slot,"aria-hidden":`true`,children:[(0,F.jsx)(`span`,{"data-workspace-leading":`folder`,className:`${kO.folder} ${t?kO.folderActive:``}`,children:i?(0,F.jsx)(xt,{size:16}):(0,F.jsx)(St,{size:16})}),(0,F.jsx)(`span`,{"data-workspace-leading":`chevron`,className:`${kO.chevron} ${i?kO.chevronOpen:``}`,children:(0,F.jsx)(ct,{size:14})})]}),(0,F.jsx)(`span`,{className:`${JO.title} ${kO.workspaceTitle}`,children:e.title}),n&&(0,F.jsx)(`span`,{className:kO.unavailable,children:r(`不可用`,`Unavailable`)})]}),(0,F.jsxs)(`span`,{className:kO.rowActions,"data-workspace-actions":!0,children:[(0,F.jsx)(AO,{title:e.title,active:t,disabled:ae,open:x===e.id,onOpenChange:t=>S(t?e.id:null),onRemove:()=>{ue(``),ce({id:e.id,title:e.title})}}),(0,F.jsx)(`button`,{type:`button`,className:kO.rowAction,title:n?r(`目录不可用,请恢复目录或移除后重新添加`,`Directory unavailable; restore it or remove and add the workspace again`):r(`新建会话`,`New session`),"aria-label":r(`在 ${e.title} 新建会话`,`Create a session in ${e.title}`),disabled:ae||n,onClick:()=>{Ce(async()=>{await h(e.id),he(``),_e(t=>new Set([...t,e.id]))})},children:(0,F.jsx)(et,{size:16})})]})]}),(0,F.jsxs)(`div`,{id:`${oe}-${e.id}`,role:`group`,"aria-label":e.title,hidden:!i,children:[i&&o.sessions.filter(t=>t.workspaceId===e.id&&(!be||e.title.toLocaleLowerCase().includes(be)||e.path.toLocaleLowerCase().includes(be)||t.name.toLocaleLowerCase().includes(be))).map(i=>{let o=t&&a?.sessionId===i.id,s=a?.sessionId===i.id?!a.idle:i.idle===!1,c=i.name||r(`新会话`,`New chat`),l={workspaceId:e.id,id:i.id,path:i.path,name:i.name,running:s};return(0,F.jsxs)(`div`,{className:kO.sessionLine,"data-menu-open":C===i.id||void 0,children:[(0,F.jsxs)(`button`,{type:`button`,className:`${JO.sessionRow} ${kO.sessionButton} ${o?JO.selected:``}`,title:c,"aria-label":c,"aria-describedby":`${oe}-${i.id}-status`,"aria-current":o?`page`:void 0,disabled:ae||n,onContextMenu:e=>{ae||n||(e.preventDefault(),e.stopPropagation(),S(null),w(i.id))},onClick:()=>{Ce(()=>m(e.id,i.id,i.path))},children:[(0,F.jsx)(`span`,{className:JO.slot,children:s&&(0,F.jsx)($e,{state:`ongoing`})}),(0,F.jsx)(`span`,{className:`${JO.title} ${i.name?``:kO.untitled}`,children:c}),(0,F.jsx)(`time`,{className:kO.sessionTime,dateTime:i.modified,title:i.modified,children:NO(i.modified,y,v)}),(0,F.jsx)(`span`,{id:`${oe}-${i.id}-status`,className:JO.visuallyHidden,children:s?r(`运行中`,`Running`):r(`空闲`,`Idle`)})]}),(0,F.jsx)(`span`,{className:kO.rowActions,children:(0,F.jsx)(jO,{title:c,disabled:ae||n,open:C===i.id,onOpenChange:e=>w(e?i.id:null),onRename:()=>{ue(``),O(i.name),E(l)},onDelete:()=>{ue(``),ee(l)}})})]},i.id)}),i&&!be&&!o.sessions.some(t=>t.workspaceId===e.id)&&(0,F.jsx)(`p`,{className:qO.empty,children:r(`还没有会话,创建新会话开始`,`No sessions yet. Create a session to start.`)})]})]},e.id)}),Se.length===0&&(0,F.jsxs)(`p`,{className:qO.empty,role:`status`,children:[be?r(`没有找到匹配的工作区或会话`,`No matching workspaces or sessions`):r(`添加工作区,开始管理对话`,`Add a workspace to start organizing conversations`),be&&(0,F.jsx)(`button`,{type:`button`,className:qO.sessionOverflowButton,onClick:xe,children:r(`清除搜索`,`Clear search`)})]}),j&&(0,F.jsx)(`p`,{className:qO.searchStatus,role:`status`,children:r(`正在处理…`,`Working…`)}),le&&!ne&&(0,F.jsx)(`p`,{className:kO.error,role:`alert`,children:le})]})})}),(0,F.jsxs)(OO,{open:se!==null,onClose:()=>{j||ce(null)},title:r(`移除工作区?`,`Remove workspace?`),closeLabel:r(`关闭`,`Close`),footer:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(EO,{variant:`outline`,disabled:j,onClick:()=>ce(null),children:r(`取消`,`Cancel`)}),(0,F.jsx)(EO,{variant:`primary`,disabled:ae,onClick:()=>{se&&Ce(async()=>{await p(se.id),ce(null)})},children:r(`从列表移除`,`Remove from list`)})]}),children:[(0,F.jsx)(`p`,{children:se?.title}),(0,F.jsx)(`p`,{children:r(`仅从侧栏移除,不删除目录、文件或会话历史。`,`Only removes it from the sidebar. Directories, files and session history are not deleted.`)}),le&&(0,F.jsx)(`p`,{role:`alert`,children:le})]}),(0,F.jsxs)(OO,{open:T!==null,onClose:()=>{j||E(null)},title:r(`重命名会话`,`Rename chat`),closeLabel:r(`关闭`,`Close`),footer:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(EO,{variant:`outline`,disabled:j,onClick:()=>E(null),children:r(`取消`,`Cancel`)}),(0,F.jsx)(EO,{variant:`primary`,type:`submit`,form:`${oe}-rename`,disabled:ae,children:r(`保存`,`Save`)})]}),children:[(0,F.jsx)(`form`,{id:`${oe}-rename`,onSubmit:e=>{e.preventDefault(),T&&Ce(async()=>{await g(T.workspaceId,T.id,T.path,D),E(null)})},children:(0,F.jsx)(`input`,{className:kO.renameInput,"aria-label":r(`会话名称`,`Chat name`),placeholder:r(`留空则使用第一条消息`,`Leave empty to use the first message`),maxLength:120,ref:te,value:D,onChange:e=>O(e.target.value)})}),le&&(0,F.jsx)(`p`,{role:`alert`,children:le})]}),(0,F.jsxs)(OO,{open:k!==null,onClose:()=>{j||ee(null)},title:r(`删除会话?`,`Delete chat?`),closeLabel:r(`关闭`,`Close`),footer:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(EO,{variant:`outline`,disabled:j,onClick:()=>ee(null),children:r(`取消`,`Cancel`)}),(0,F.jsx)(EO,{variant:`primary`,disabled:ae||k?.running,onClick:()=>{k&&Ce(async()=>{await _(k.workspaceId,k.id,k.path),ee(null)})},children:r(`删除`,`Delete`)})]}),children:[(0,F.jsx)(`p`,{children:k?.name||r(`新会话`,`New chat`)}),(0,F.jsx)(`p`,{children:k?.running?r(`Pi 正在运行,请等待当前回复结束后再删除。`,`Pi is still working. Wait for the reply to finish before deleting.`):r(`会话会从列表中移除,文件移到 Pi 数据目录的 pi-web/trash 中,可手动恢复。项目文件不受影响。`,`The chat leaves the list and its file moves to pi-web/trash in the Pi data folder, where you can restore it by hand. Project files are not affected.`)}),le&&(0,F.jsx)(`p`,{role:`alert`,children:le})]}),(0,F.jsx)(KO,{open:ne,busy:j,listDirectory:d,createDirectory:f,onOpen:e=>{we(e)},onClose:()=>{j||A(!1)},t:YO}),(0,F.jsx)(OO,{open:!!de,onClose:()=>fe(``),title:r(`无法添加工作区`,`Could not add workspace`),closeLabel:r(`关闭`,`Close`),footer:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(EO,{variant:`outline`,onClick:()=>fe(``),children:r(`取消`,`Cancel`)}),(0,F.jsx)(EO,{variant:`primary`,onClick:()=>{fe(``),Te()},children:r(`重新选择`,`Choose again`)})]}),children:(0,F.jsx)(`div`,{role:`alert`,children:de})})]})}function ZO(e){let t=e.trim();if(!t)return;let n=/^(\d+(?:\.\d+)?)([km])?$/i.exec(t);if(!n)return NaN;let r=n[2]?.toLowerCase(),i=r===`m`?1e6:r===`k`?1e3:1,a=Number(n[1])*i,o=Math.round(a);return Math.abs(a-o)<1e-6?o:a}function QO(e){return e===void 0?``:!Number.isInteger(e)||e<=0?String(e):e%1e6==0?`${e/1e6}M`:e%1e3==0?`${e/1e3}K`:String(e)}function $O({model:e,position:t,onSave:n,onRemove:i,onCancel:a}){let[o,s]=(0,P.useState)(e.id),[c,l]=(0,P.useState)(e.name??``),[u,d]=(0,P.useState)(QO(e.contextWindow)),[f,p]=(0,P.useState)(QO(e.maxTokens)),[m,h]=(0,P.useState)(e.input?.length?e.input:[`text`]),[g,_]=(0,P.useState)(!e.id),[v,y]=(0,P.useState)(!1),[b,x]=(0,P.useState)(!1),[S,C]=(0,P.useState)(``),w=!e.id,T=!w&&(e.source===`custom`||e.overridden),E=async()=>{let e=ZO(u),t=ZO(f);if(!o.trim()||[e,t].some(e=>e!==void 0&&(!Number.isSafeInteger(e)||e<=0)))C(r(`请填写模型 ID,并使用正整数或 K/M 单位填写容量。`,`Enter a model ID and positive token counts, optionally with K/M suffixes.`));else{x(!0),C(``);try{await n({id:o.trim(),...c.trim()?{name:c.trim()}:{},...e===void 0?{}:{contextWindow:e},...t===void 0?{}:{maxTokens:t},input:m})}catch(e){C(e instanceof Error?e.message:r(`保存失败`,`Could not save`))}finally{x(!1)}}},D=async()=>{x(!0),C(``);try{await i()}catch(e){C(e instanceof Error?e.message:r(`操作失败`,`Action failed`)),y(!1)}finally{x(!1)}},O=e=>{h(t=>{let n=t.includes(e)?t.filter(t=>t!==e):[...t,e];return n.length?n:t})};return(0,F.jsxs)(`div`,{className:`pi-model-entry`,children:[(0,F.jsxs)(`div`,{className:`pi-model-row`,children:[(0,F.jsx)(`input`,{"aria-label":`${r(`模型 ID`,`Model ID`)} ${t}`,placeholder:r(`模型 ID`,`Model ID`),value:o,disabled:b||!w&&e.source===`builtin`,onFocus:()=>_(!0),onChange:e=>s(e.target.value)}),(0,F.jsx)(`input`,{"aria-label":`${r(`显示名称`,`Display name`)} ${t}`,placeholder:r(`显示名称`,`Display name`),value:c,disabled:b,onFocus:()=>_(!0),onChange:e=>l(e.target.value)}),(0,F.jsx)(`button`,{type:`button`,"aria-label":`${r(`模型参数`,`Model settings`)} ${t}`,"aria-expanded":g,onClick:()=>_(!g),children:g?`⌄`:`›`})]}),g&&(0,F.jsxs)(`div`,{className:`pi-model-details`,children:[(0,F.jsxs)(`label`,{children:[r(`上下文窗口`,`Context window`),(0,F.jsx)(`input`,{"aria-label":`${r(`上下文窗口`,`Context window`)} ${t}`,inputMode:`decimal`,placeholder:`128K`,value:u,disabled:b,onChange:e=>d(e.target.value)})]}),(0,F.jsxs)(`label`,{children:[r(`最大输出 token 数`,`Max output tokens`),(0,F.jsx)(`input`,{"aria-label":`${r(`最大输出 token 数`,`Max output tokens`)} ${t}`,inputMode:`decimal`,placeholder:`16K`,value:f,disabled:b,onChange:e=>p(e.target.value)})]}),(0,F.jsxs)(`fieldset`,{className:`pi-model-input-types`,children:[(0,F.jsx)(`legend`,{children:r(`输入类型`,`Input types`)}),(0,F.jsxs)(`label`,{children:[(0,F.jsx)(`input`,{type:`checkbox`,checked:m.includes(`text`),disabled:b||m.length===1&&m.includes(`text`),onChange:()=>O(`text`)}),r(`文本`,`Text`)]}),(0,F.jsxs)(`label`,{children:[(0,F.jsx)(`input`,{type:`checkbox`,checked:m.includes(`image`),disabled:b||m.length===1&&m.includes(`image`),onChange:()=>O(`image`)}),r(`图片`,`Image`)]})]}),(0,F.jsxs)(`div`,{className:`pi-model-actions`,children:[(0,F.jsx)(`button`,{type:`button`,disabled:b,onClick:()=>{E()},children:b?r(`保存中…`,`Saving…`):r(`保存模型`,`Save model`)}),w&&a&&(0,F.jsx)(`button`,{type:`button`,disabled:b,onClick:a,children:r(`取消`,`Cancel`)}),T&&(0,F.jsx)(`button`,{type:`button`,disabled:b,onClick:()=>y(!v),children:e.source===`custom`?r(`移除模型`,`Remove model`):r(`恢复默认`,`Restore default`)})]}),v&&(0,F.jsxs)(`div`,{className:`pi-model-confirm`,children:[(0,F.jsx)(`span`,{children:e.source===`custom`?r(`从配置中移除这个模型?`,`Remove this model from configuration?`):r(`撤销这个模型的自定义参数?`,`Discard this model’s custom settings?`)}),(0,F.jsx)(`button`,{type:`button`,disabled:b,onClick:()=>{D()},children:r(`确认`,`Confirm`)}),(0,F.jsx)(`button`,{type:`button`,disabled:b,onClick:()=>y(!1),children:r(`取消`,`Cancel`)})]}),S&&(0,F.jsx)(`p`,{className:`pi-settings-error`,role:`alert`,children:S})]})]})}function ek({providerId:e,getModels:t,updateModel:n}){let[i,a]=(0,P.useState)(null),[o,s]=(0,P.useState)(``),[c,l]=(0,P.useState)(``),[u,d]=(0,P.useState)(!1),f=async()=>{s(``);try{a(await t(e))}catch(e){throw s(e instanceof Error?e.message:r(`无法读取模型目录`,`Could not load model catalog`)),e}};(0,P.useEffect)(()=>{f().catch(()=>{})},[e]);let p=async t=>{await n(e,t),d(!1),await f().catch(()=>{})},m=i?.models.filter(e=>`${e.id} ${e.name??``}`.toLocaleLowerCase().includes(c.toLocaleLowerCase()))??[];return(0,F.jsxs)(`section`,{className:`pi-provider-models`,"aria-label":r(`模型目录`,`Model catalog`),children:[(0,F.jsxs)(`div`,{className:`pi-provider-models-head`,children:[(0,F.jsx)(`strong`,{children:r(`模型目录`,`Model catalog`)}),(0,F.jsxs)(`span`,{children:[i?.models.length??0,` `,r(`个模型`,`models`)]})]}),i?.baseUrl&&(0,F.jsxs)(`p`,{className:`pi-provider-models-endpoint`,title:i.baseUrl,children:[r(`API 地址`,`API URL`),`: `,i.baseUrl]}),o&&(0,F.jsxs)(`p`,{className:`pi-settings-error`,role:`alert`,children:[o,` `,i&&(0,F.jsx)(`button`,{type:`button`,onClick:()=>{f().catch(()=>{})},children:r(`重试读取`,`Retry`)})]}),i?(0,F.jsxs)(F.Fragment,{children:[i.models.length>5&&(0,F.jsx)(`input`,{className:`pi-model-search`,type:`search`,"aria-label":r(`搜索模型`,`Search models`),placeholder:r(`搜索模型`,`Search models`),value:c,onChange:e=>l(e.target.value)}),(0,F.jsx)(`div`,{className:`pi-model-list`,children:m.map((e,t)=>(0,F.jsx)($O,{model:e,position:t+1,onSave:t=>p({action:`save`,originalId:e.id,model:t}),onRemove:()=>p({action:`remove`,id:e.id})},`${e.id}:${e.name}:${e.contextWindow}:${e.maxTokens}:${e.overridden}`))}),m.length===0&&!u&&(0,F.jsx)(`p`,{className:`pi-provider-models-empty`,children:r(`没有匹配的模型`,`No matching models`)}),u&&(0,F.jsx)($O,{model:{id:``,source:`custom`,overridden:!1},position:i.models.length+1,onSave:e=>p({action:`save`,model:e}),onRemove:async()=>d(!1),onCancel:()=>d(!1)},`new`),!u&&(0,F.jsx)(`button`,{type:`button`,className:`pi-model-add`,onClick:()=>d(!0),children:r(`+ 添加模型`,`+ Add model`)})]}):o?(0,F.jsx)(`button`,{type:`button`,className:`pi-model-add`,onClick:()=>{f().catch(()=>{})},children:r(`重试读取`,`Retry`)}):(0,F.jsx)(`p`,{role:`status`,children:r(`正在读取模型…`,`Loading models…`)})]})}var tk={id:``,name:``,baseUrl:``,api:`openai-completions`,modelId:``};function nk(e){try{let t=new URL(e);return t.protocol===`https:`||t.protocol===`http:`?t.href:null}catch{return null}}function rk(){let e=null;try{return e=window.open(`about:blank`,`_blank`),e&&(e.opener=null,e.document.title=r(`正在准备授权页面`,`Preparing sign-in`),e.document.body.textContent=r(`正在准备授权页面…`,`Preparing sign-in…`)),e}catch{return e?.close(),null}}function ik({provider:e,configured:t,busy:n,getProviderModels:i,updateProviderModel:a,onConnect:o}){let[s,c]=(0,P.useState)(``),[l,u]=(0,P.useState)(``),[d,f]=(0,P.useState)(``),[p,m]=(0,P.useState)(!0),[h,g]=(0,P.useState)(!1),[_,v]=(0,P.useState)(``);(0,P.useEffect)(()=>{let t=!0;return m(!0),i(e.id).then(e=>{t&&(u(e.baseUrl??``),f(e.baseUrl??``),m(!1))}).catch(e=>{t&&(m(!1),v(e instanceof Error?e.message:r(`无法读取 API 地址`,`Could not load API URL`)))}),()=>{t=!1}},[e.id]);let y=async()=>{let n=s.trim(),i=l.trim();if(n||t){if(i&&!nk(i))v(r(`请输入有效的 http 或 https 地址。`,`Enter a valid HTTP or HTTPS URL.`));else{g(!0),v(``);try{i!==d&&(await a(e.id,{action:`base_url`,baseUrl:i||null}),f(i)),n&&(c(``),await o(n))}catch(e){v(e instanceof Error?e.message:r(`保存失败`,`Could not save`))}finally{g(!1)}}}};return(0,F.jsxs)(`form`,{className:`pi-provider-key-form`,onSubmit:e=>{e.preventDefault(),y()},children:[(0,F.jsxs)(`label`,{children:[r(`API Key`,`API key`),(0,F.jsx)(`input`,{type:`password`,autoComplete:`off`,maxLength:16384,value:s,onChange:e=>c(e.target.value),placeholder:t?r(`已配置,输入新值可替换`,`Configured; enter a new key to replace`):r(`输入 API Key`,`Enter API key`)})]}),(0,F.jsxs)(`details`,{className:`pi-provider-advanced`,children:[(0,F.jsx)(`summary`,{children:r(`自定义设置`,`Custom settings`)}),(0,F.jsxs)(`label`,{children:[r(`API 地址(可选)`,`API URL (optional)`),(0,F.jsx)(`input`,{type:`url`,maxLength:2048,value:l,onChange:e=>u(e.target.value),placeholder:r(`使用提供方默认地址`,`Use provider default URL`)})]})]}),(0,F.jsx)(`button`,{type:`submit`,disabled:n||h||p||!s.trim()&&(l.trim()===d||!t),children:h?r(`保存中…`,`Saving…`):t?r(`保存`,`Save`):r(`连接`,`Connect`)}),_&&(0,F.jsx)(`p`,{className:`pi-settings-error`,role:`alert`,children:_})]})}function ak({setupMode:e=!1,onReturnToConversation:t,getProviders:n,getProviderModels:i,updateProviderModel:a,logoutProvider:o,addCustomProvider:s,startLogin:c,getLogin:l,getActiveLogin:u,respondLogin:d,cancelLogin:f,refreshModels:p}){let[m,h]=(0,P.useState)([]),[g,_]=(0,P.useState)(!1),[v,y]=(0,P.useState)(e?`builtin`:null),[b,x]=(0,P.useState)(``),[S,C]=(0,P.useState)(null),[w,T]=(0,P.useState)(null),[E,D]=(0,P.useState)(tk),[O,k]=(0,P.useState)(null),[ee,te]=(0,P.useState)(``),[ne,A]=(0,P.useState)(``),[re,ie]=(0,P.useState)(!1),j=(0,P.useRef)(null);(0,P.useEffect)(()=>{e&&y(e=>e??`builtin`)},[e]),(0,P.useEffect)(()=>{let e=!0;return u().then(t=>{e&&t&&k(e=>e??t)}).catch(()=>{}),()=>{e=!1,j.current?.popup?.close()}},[]);let ae=async()=>{h(await n()),_(!0)},oe=async e=>{let t=j.current,n=e.authorization??(e.event?.type===`auth_url`||e.event?.type===`device_code`?e.event:void 0);if(t?.id===e.id&&n){let e=nk(n.type===`auth_url`?n.url:n.verificationUri);if(e){try{t.popup&&!t.popup.closed?t.popup.location.replace(e):window.open(e,`_blank`,`noopener,noreferrer`)}catch{t.popup?.close()}j.current=null}}t?.id===e.id&&(e.status===`done`||e.status===`error`||e.status===`cancelled`)&&(t.popup?.close(),j.current=null),k(e),e.status===`done`&&(y(null),C(null),await Promise.all([ae(),p()]))};(0,P.useEffect)(()=>{ae().catch(e=>{_(!0),A(e instanceof Error?e.message:r(`无法读取模型提供方`,`Could not load model providers`))})},[]),(0,P.useEffect)(()=>{if(!O||O.status===`done`||O.status===`error`||O.status===`cancelled`)return;let e=!0,t=window.setInterval(()=>{l(O.id).then(async t=>{e&&await oe(t)}).catch(t=>{e&&A(t instanceof Error?t.message:r(`登录状态不可用`,`Login status is unavailable`))})},700);return()=>{e=!1,window.clearInterval(t)}},[O?.id,O?.status]);let M=re||O?.status===`running`||O?.status===`waiting`,se=m.find(e=>e.id===O?.providerId)?.name,ce=m.filter(e=>e.configured),le=m.filter(e=>!e.configured&&e.methods.length>0),ue=le.find(e=>e.id===b)??(e?le.find(e=>e.id===`openai-codex`)??le.find(e=>e.methods.includes(`oauth`)):void 0)??le.find(e=>e.id===`openai`)??le[0],de=async(e,t,n)=>{j.current=t===`oauth`?{id:null,popup:rk()}:null,ie(!0),A(``),te(``);try{let{id:r}=await c(e,t,n);j.current&&(j.current.id=r),await oe(await l(r))}catch(e){j.current?.popup?.close(),j.current=null,A(e instanceof Error?e.message:r(`无法开始登录`,`Could not start sign-in`)),O||u().then(e=>{e&&k(e)}).catch(()=>{})}finally{ie(!1)}},fe=async e=>{if(O){ie(!0),A(``);try{await d(O.id,e),te(``),await oe(await l(O.id))}catch(e){A(e instanceof Error?e.message:r(`提交失败`,`Submission failed`))}finally{ie(!1)}}},pe=async()=>{ie(!0),A(``);try{await s(E);let e=E.id;await ae(),x(e),y(`builtin`),D(tk)}catch(e){A(e instanceof Error?e.message:r(`无法添加自定义提供方`,`Could not add custom provider`))}finally{ie(!1)}},me=async e=>{ie(!0),A(``);try{await o(e),await ae(),T(null),C(null)}catch(e){A(e instanceof Error?e.message:r(`移除认证失败`,`Could not remove credentials`))}finally{ie(!1)}},N=O?.authorization??(O?.event?.type===`auth_url`||O?.event?.type===`device_code`?O.event:void 0),he=O?.status===`waiting`&&O.prompt&&O.prompt.type!==`select`&&(0,F.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),ee.trim()&&fe(ee.trim())},children:[(0,F.jsx)(`label`,{htmlFor:`pi-provider-answer`,children:O.prompt.message}),(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`input`,{id:`pi-provider-answer`,type:O.prompt.type===`secret`?`password`:`text`,autoComplete:`off`,placeholder:O.prompt.placeholder,value:ee,onChange:e=>te(e.target.value)}),(0,F.jsx)(`button`,{type:`submit`,disabled:re||!ee.trim(),children:r(`继续`,`Continue`)})]})]});return(0,F.jsxs)(`div`,{className:`pi-settings-content`,children:[(0,F.jsx)(`h2`,{children:e?r(`先连接一个模型`,`Connect a model to begin`):r(`模型`,`Models`)}),(0,F.jsx)(`p`,{className:`pi-settings-intro`,children:e?r(`当前没有可用模型。选择提供方完成认证,再在会话中选择模型;也可以添加自定义提供方。`,`No models are available yet. Sign in to a provider, then choose a model in the conversation. You can also add a custom provider.`):r(`已接入的提供方显示在这里。添加新的提供方后,即可在会话中选择其模型。`,`Connected providers appear here. Add a provider to use its models in a conversation.`)}),ne&&(0,F.jsx)(`p`,{className:`pi-settings-error`,role:`alert`,children:ne}),O&&(0,F.jsxs)(`section`,{className:`pi-provider-flow`,"aria-label":r(`模型登录`,`Model sign-in`),children:[(0,F.jsxs)(`div`,{className:`pi-provider-flow-head`,children:[(0,F.jsxs)(`strong`,{children:[r(`模型登录`,`Model sign-in`),se?` · ${se}`:``]}),(0,F.jsx)(`button`,{type:`button`,onClick:()=>{j.current?.id===O.id&&(j.current.popup?.close(),j.current=null),O.status===`running`||O.status===`waiting`?f(O.id).finally(()=>k(null)):k(null)},children:O.status===`running`||O.status===`waiting`?r(`取消`,`Cancel`):r(`关闭`,`Close`)})]}),O.status===`done`&&(0,F.jsxs)(`div`,{role:`status`,children:[(0,F.jsx)(`p`,{children:r(`已连接。现在可以在会话中选择该提供方的模型。`,`Connected. You can now select this provider’s models in a conversation.`)}),(0,F.jsx)(`button`,{type:`button`,onClick:t,children:r(`返回会话选择模型`,`Return to conversation and choose a model`)})]}),O.status===`error`&&(0,F.jsx)(`p`,{role:`alert`,children:O.error}),O.status===`running`&&!N&&(0,F.jsx)(`p`,{role:`status`,children:r(`正在等待提供方响应…`,`Waiting for the provider…`)}),O.event?.type===`info`&&(0,F.jsxs)(`p`,{children:[O.event.message,O.event.links?.map(e=>{let t=nk(e.url);return t&&(0,F.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,children:e.label??r(`打开链接`,`Open link`)},t)})]}),O.event?.type===`progress`&&N?.type!==`auth_url`&&(0,F.jsx)(`p`,{children:O.event.message}),N?.type===`auth_url`&&(0,F.jsxs)(`p`,{role:`status`,children:[r(`请在授权页面完成登录;若页面未自动打开,请点击右侧链接。完成后这里会自动更新。`,`Complete sign-in on the authorization page. If it did not open, use the link. This page will update automatically.`),` `,nk(N.url)&&(0,F.jsx)(`a`,{href:nk(N.url),target:`_blank`,rel:`noopener noreferrer`,children:r(`打开授权页面`,`Open authorization page`)})]}),N?.type===`device_code`&&(0,F.jsxs)(`p`,{children:[r(`在`,`On the`),` `,nk(N.verificationUri)&&(0,F.jsx)(`a`,{href:nk(N.verificationUri),target:`_blank`,rel:`noopener noreferrer`,children:r(`验证页面`,`verification page`)}),` `,r(`输入代码`,`enter code`),` `,(0,F.jsx)(`code`,{children:N.userCode})]}),O.status===`waiting`&&O.prompt?.type===`select`&&(0,F.jsxs)(`div`,{className:`pi-provider-options`,children:[(0,F.jsx)(`p`,{children:O.prompt.message}),O.prompt.options.map(e=>(0,F.jsxs)(`button`,{type:`button`,disabled:re,onClick:()=>{fe(e.id)},children:[e.label,e.description&&(0,F.jsx)(`small`,{children:e.description})]},e.id))]}),he&&O.prompt?.type===`manual_code`&&N?.type===`auth_url`?(0,F.jsxs)(`details`,{className:`pi-provider-manual-login`,children:[(0,F.jsx)(`summary`,{children:r(`无法自动完成?手动输入授权码`,`Can't finish automatically? Enter an authorization code`)}),he]}):he]}),(0,F.jsxs)(`section`,{className:`pi-provider-list`,"aria-label":r(`已接入的模型提供方`,`Connected model providers`),children:[ce.map(e=>(0,F.jsxs)(`div`,{className:`pi-provider-card`,children:[(0,F.jsxs)(`div`,{className:`pi-provider-card-head`,children:[(0,F.jsxs)(`span`,{className:`pi-provider-name`,children:[e.name,(0,F.jsx)(`span`,{className:`pi-provider-dot`,role:`img`,"aria-label":r(`已配置认证`,`Authentication configured`)}),(0,F.jsx)(`small`,{children:r(`已配置`,`Configured`)})]}),(0,F.jsx)(`button`,{type:`button`,disabled:M,"aria-label":`${r(`编辑`,`Edit`)} ${e.name}`,"aria-expanded":S===e.id,onClick:()=>{y(null),C(S===e.id?null:e.id)},children:r(`编辑`,`Edit`)})]}),S===e.id&&(0,F.jsxs)(`div`,{className:`pi-provider-editor`,children:[e.methods.includes(`api_key`)&&(0,F.jsx)(ik,{provider:e,configured:!0,busy:!!M,getProviderModels:i,updateProviderModel:a,onConnect:t=>de(e.id,`api_key`,t)},e.id),e.methods.includes(`oauth`)&&(0,F.jsx)(`div`,{className:`pi-provider-methods`,children:(0,F.jsx)(`button`,{type:`button`,disabled:!!M,onClick:()=>{de(e.id,`oauth`)},children:r(`网页登录`,`Browser sign-in`)})}),(0,F.jsx)(ek,{providerId:e.id,getModels:i,updateModel:a}),e.storedCredential&&(0,F.jsx)(`div`,{className:`pi-provider-credential-action`,children:(0,F.jsx)(`button`,{type:`button`,disabled:M,onClick:()=>T(e.id),children:r(`移除认证`,`Remove credentials`)})}),!e.storedCredential&&(0,F.jsx)(`p`,{className:`pi-provider-auth-source`,children:r(`当前认证来自环境变量、模型配置或其他运行时来源,请在对应位置移除。`,`Authentication comes from an environment variable, model configuration, or another runtime source. Remove it at its source.`)}),w===e.id&&(0,F.jsxs)(`div`,{className:`pi-model-confirm`,role:`group`,"aria-label":r(`确认移除认证`,`Confirm credential removal`),children:[(0,F.jsx)(`span`,{children:r(`移除本机保存的认证后,该模型可能无法继续使用。`,`Removing stored credentials may make this provider unavailable.`)}),(0,F.jsx)(`button`,{type:`button`,disabled:re,onClick:()=>{me(e.id)},children:r(`确认移除`,`Remove`)}),(0,F.jsx)(`button`,{type:`button`,disabled:re,onClick:()=>T(null),children:r(`取消`,`Cancel`)})]})]})]},e.id)),g&&ce.length===0&&(0,F.jsx)(`p`,{className:`pi-provider-empty`,children:r(`尚未接入提供方`,`No providers connected yet`)}),!g&&(0,F.jsx)(`p`,{role:`status`,children:r(`正在读取模型提供方…`,`Loading model providers…`)})]}),v===`builtin`&&(0,F.jsxs)(`section`,{className:`pi-provider-add-card`,"aria-label":r(`添加提供方`,`Add provider`),children:[(0,F.jsxs)(`div`,{className:`pi-provider-flow-head`,children:[(0,F.jsx)(`strong`,{children:r(`添加提供方`,`Add provider`)}),(0,F.jsx)(`button`,{type:`button`,onClick:()=>y(null),children:r(`关闭`,`Close`)})]}),ue?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`label`,{htmlFor:`pi-provider-select`,children:r(`提供方`,`Provider`)}),(0,F.jsx)(`select`,{id:`pi-provider-select`,value:ue.id,onChange:e=>x(e.target.value),children:le.map(e=>(0,F.jsx)(`option`,{value:e.id,children:e.name},e.id))}),ue.methods.includes(`api_key`)&&(0,F.jsx)(ik,{provider:ue,configured:!1,busy:!!M,getProviderModels:i,updateProviderModel:a,onConnect:e=>de(ue.id,`api_key`,e)},ue.id),ue.methods.includes(`oauth`)&&(0,F.jsx)(`div`,{className:`pi-provider-methods`,children:(0,F.jsx)(`button`,{type:`button`,disabled:!!M,onClick:()=>{de(ue.id,`oauth`)},children:r(`网页登录`,`Browser sign-in`)})}),(0,F.jsx)(`p`,{children:r(`认证完成后,可在提供方的“编辑”中调整模型目录。`,`After sign-in, open the provider’s Edit panel to adjust its model catalog.`)})]}):(0,F.jsx)(`p`,{children:r(`没有可添加的提供方。`,`No providers can be added.`)})]}),v===`custom`&&(0,F.jsxs)(`section`,{className:`pi-provider-add-card`,"aria-label":r(`添加自定义提供方`,`Add custom provider`),children:[(0,F.jsxs)(`div`,{className:`pi-provider-flow-head`,children:[(0,F.jsx)(`strong`,{children:r(`添加自定义提供方`,`Add custom provider`)}),(0,F.jsx)(`button`,{type:`button`,onClick:()=>y(null),children:r(`关闭`,`Close`)})]}),(0,F.jsx)(`p`,{children:r(`适用于兼容 Pi 已支持协议的模型服务。保存后再添加 API Key;密钥不会写入 models.json。`,`For model services compatible with Pi’s supported protocols. Add an API key after saving; it will not be written to models.json.`)}),(0,F.jsxs)(`form`,{className:`pi-provider-custom-form`,onSubmit:e=>{e.preventDefault(),pe()},children:[(0,F.jsxs)(`label`,{children:[r(`名称`,`Name`),(0,F.jsx)(`input`,{required:!0,maxLength:100,value:E.name,onChange:e=>D({...E,name:e.target.value}),placeholder:r(`我的模型服务`,`My model service`)})]}),(0,F.jsxs)(`label`,{children:[r(`提供方 ID`,`Provider ID`),(0,F.jsx)(`input`,{required:!0,maxLength:64,value:E.id,onChange:e=>D({...E,id:e.target.value}),placeholder:`my-provider`})]}),(0,F.jsxs)(`label`,{children:[r(`接口地址`,`API URL`),(0,F.jsx)(`input`,{required:!0,type:`url`,maxLength:2048,value:E.baseUrl,onChange:e=>D({...E,baseUrl:e.target.value}),placeholder:`https://api.example.com/v1`})]}),(0,F.jsxs)(`label`,{children:[r(`接口协议`,`API protocol`),(0,F.jsxs)(`select`,{value:E.api,onChange:e=>D({...E,api:e.target.value}),children:[(0,F.jsx)(`option`,{value:`openai-completions`,children:`OpenAI Chat Completions`}),(0,F.jsx)(`option`,{value:`openai-responses`,children:`OpenAI Responses`}),(0,F.jsx)(`option`,{value:`anthropic-messages`,children:`Anthropic Messages`})]})]}),(0,F.jsxs)(`label`,{children:[r(`模型 ID`,`Model ID`),(0,F.jsx)(`input`,{required:!0,maxLength:200,value:E.modelId,onChange:e=>D({...E,modelId:e.target.value}),placeholder:`model-name`})]}),(0,F.jsx)(`button`,{type:`submit`,disabled:re,children:r(`保存并继续`,`Save and continue`)})]})]}),!v&&(0,F.jsxs)(`div`,{className:`pi-provider-add-actions`,children:[(0,F.jsx)(`button`,{type:`button`,disabled:!g||le.length===0||M,onClick:()=>{C(null),y(`builtin`),x(``)},children:r(`+ 添加提供方`,`+ Add provider`)}),(0,F.jsx)(`button`,{type:`button`,disabled:M,onClick:()=>{C(null),y(`custom`)},children:r(`+ 添加自定义提供方`,`+ Add custom provider`)})]})]})}var ok=`pi-web-theme`,sk=new Set,ck=window.matchMedia(`(prefers-color-scheme: dark)`),lk=uk();function uk(){try{let e=localStorage.getItem(ok);if(e===`light`||e===`dark`||e===`system`)return e}catch{}return`system`}function dk(){document.body.toggleAttribute(`data-ds-dark-theme`,lk===`dark`||lk===`system`&&ck.matches)}function fk(){dk(),ck.addEventListener(`change`,dk),window.addEventListener(`storage`,e=>{e.key===ok&&(lk=uk(),dk(),sk.forEach(e=>e()))})}function pk(e){lk=e;try{localStorage.setItem(ok,e)}catch{}dk(),sk.forEach(e=>e())}function mk(){return(0,P.useSyncExternalStore)(e=>(sk.add(e),()=>{sk.delete(e)}),()=>lk)}var hk={group:`_group_8jvbt_4`,title:`_title_8jvbt_12`,cubeRow:`_cubeRow_8jvbt_19`,themeCube:`_themeCube_8jvbt_29`,selected:`_selected_8jvbt_48`};function gk(){let e=mk(),t=l(),r=[{id:`light`,label:t===`zh`?`浅色`:`Light`,Icon:Ct},{id:`dark`,label:t===`zh`?`深色`:`Dark`,Icon:wt},{id:`system`,label:t===`zh`?`跟随系统`:`System`,Icon:Tt}];return(0,F.jsxs)(`div`,{className:hk.group,children:[(0,F.jsx)(`div`,{className:hk.title,children:t===`zh`?`外观`:`Appearance`}),(0,F.jsx)(`div`,{className:hk.cubeRow,children:r.map(({id:t,label:r,Icon:i})=>(0,F.jsxs)(`button`,{type:`button`,className:n(hk.themeCube,e===t&&hk.selected),"aria-pressed":e===t,onClick:()=>pk(t),children:[(0,F.jsx)(i,{}),r]},t))})]})}var _k={selectorWrap:`_selectorWrap_5eqgx_1`,selector:`_selector_5eqgx_1`,value:`_value_5eqgx_23`,option:`_option_5eqgx_24`,chevron:`_chevron_5eqgx_25`,menu:`_menu_5eqgx_27`};function vk({label:e,menuLabel:t,value:n,options:r,disabled:i,onChange:a}){let[o,s]=(0,P.useState)(!1),c=(0,P.useId)(),l=(0,P.useRef)(null),u=(0,P.useRef)(null),d=(0,P.useRef)(null);return(0,P.useEffect)(()=>{i&&s(!1)},[i]),(0,P.useEffect)(()=>{if(!o)return;d.current?.focus();let e=e=>{l.current?.contains(e.target)||s(!1)},t=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopImmediatePropagation(),s(!1),u.current?.focus())};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[o]),(0,F.jsxs)(`div`,{className:_k.selectorWrap,ref:l,onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||s(!1)},children:[(0,F.jsxs)(`button`,{ref:u,type:`button`,className:_k.selector,"aria-label":e,"aria-haspopup":`menu`,"aria-expanded":o,"aria-controls":o?c:void 0,disabled:i,onClick:()=>s(e=>!e),children:[(0,F.jsx)(`span`,{className:_k.value,children:r.find(e=>e.id===n)?.label}),(0,F.jsx)(`svg`,{className:_k.chevron,width:`14`,height:`14`,viewBox:`0 0 14 14`,fill:`none`,"aria-hidden":`true`,children:(0,F.jsx)(`path`,{d:`m3.5 5.25 3.5 3.5 3.5-3.5`,stroke:`currentColor`,strokeWidth:`1.4`,strokeLinecap:`round`,strokeLinejoin:`round`})})]}),o&&(0,F.jsx)(`div`,{id:c,className:_k.menu,role:`menu`,"aria-label":t,onKeyDown:e=>{if(![`ArrowDown`,`ArrowUp`,`Home`,`End`].includes(e.key))return;e.preventDefault();let t=Array.from(e.currentTarget.querySelectorAll(`[role="menuitemradio"]`)),n=t.indexOf(document.activeElement);t[e.key===`Home`?0:e.key===`End`?t.length-1:(n+(e.key===`ArrowDown`?1:t.length-1))%t.length]?.focus()},children:r.map(e=>(0,F.jsxs)(`button`,{ref:e.id===n?d:void 0,type:`button`,role:`menuitemradio`,"aria-checked":e.id===n,className:_k.option,onClick:()=>{s(!1),u.current?.focus(),e.id!==n&&a(e.id)},children:[(0,F.jsx)(`span`,{children:e.label}),e.id===n&&(0,F.jsx)(`svg`,{className:_k.chevron,width:`16`,height:`16`,viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,children:(0,F.jsx)(`path`,{d:`m3 8 3.2 3.2L13 4.5`,stroke:`currentColor`,strokeWidth:`1.7`,strokeLinecap:`round`,strokeLinejoin:`round`})})]},e.id))})]})}var yk={row:`_row_1rrpk_1`,title:`_title_1rrpk_9`},bk=[{id:`zh`,label:`中文`},{id:`en`,label:`English`}];function xk(){let e=l(),t=e===`zh`?`语言`:`Language`;return(0,F.jsxs)(`div`,{className:yk.row,children:[(0,F.jsx)(`div`,{className:yk.title,children:t}),(0,F.jsx)(vk,{label:t,menuLabel:e===`zh`?`选择语言`:`Choose language`,value:e,options:bk,onChange:i})]})}function Sk(e,t,n){return e instanceof m&&e.status===404?t===`zh`?`后台服务仍在运行旧版。请重启 pi-webapp 后重新打开页面,再检查更新。`:`The background service is still running an older version. Restart pi-webapp, reopen this page, then check again.`:e instanceof Error&&e.message?e.message:n===`check`?t===`zh`?`检查更新失败`:`Could not check for updates`:t===`zh`?`升级失败`:`Update failed`}function Ck({getUpdate:e,getRunningVersion:t,setUpdateChannel:n,cancelUpdate:r,update:i}){let a=l(),[o,s]=(0,P.useState)(null),[c,u]=(0,P.useState)(!0),[d,p]=(0,P.useState)(!1),[m,h]=(0,P.useState)(!1),[g,_]=(0,P.useState)(null),[v,y]=(0,P.useState)(!1),[b,x]=(0,P.useState)(``),S=(0,P.useRef)(!1),C=(0,P.useRef)(!1),w=(0,P.useRef)(0),T=(0,P.useRef)(!0);(0,P.useEffect)(()=>(T.current=!0,()=>{T.current=!1}),[]);let E=async()=>{let t=++w.current;u(!0),x(``);try{let n=await e();T.current&&t===w.current&&s(n)}catch(e){T.current&&t===w.current&&(s(null),x(Sk(e,a,`check`)))}finally{T.current&&t===w.current&&u(!1)}};return(0,P.useEffect)(()=>{E();let e=()=>{E()};return window.addEventListener(`pi-update-channel`,e),()=>{window.removeEventListener(`pi-update-channel`,e)}},[]),(0,P.useEffect)(()=>{if(!g)return;let e=!1,n=new AbortController,r,i=setTimeout(()=>{e=!0,n.abort(),clearTimeout(r),_(null),y(!0),x(f(a,`新版未能及时就绪,后台可能已回退到旧版。请刷新页面检查当前版本;若无法连接,请重新打开应用。`,`The new version was not ready in time; the backend may have rolled back. Refresh to check the running version, or reopen the app if disconnected.`)),_e(Error(`Updated service did not become ready within 60 seconds`),{stage:`update_restart`,code:`update_restart_timeout`,route:`/api/update/version`,timeoutMs:6e4})},6e4),o=async()=>{try{let r=await t(n.signal);if(e)return;if(r.current===g){clearTimeout(i),location.reload();return}}catch{}e||(r=setTimeout(()=>{o()},1200))};return r=setTimeout(()=>{o()},1200),()=>{e=!0,n.abort(),clearTimeout(r),clearTimeout(i)}},[g]),{status:o,checking:c,installing:d,cancelling:m,targetVersion:g,restartTimedOut:v,error:b,check:E,install:async()=>{if(S.current||c||!o?.available||!o.canRestart||g||v||o.downgrade&&!window.confirm(f(a,`将从 ${o.current} 切换至稳定版 ${o.latest}。部分新功能可能不可用;请先备份重要数据。是否继续?`,`Switch from ${o.current} to stable ${o.latest}? Some new features may be unavailable. Back up important data before continuing.`)))return;S.current=!0,p(!0),x(``);let t=o.channel&&o.latest?{channel:o.channel,version:o.latest,...o.downgrade?{allowDowngrade:!0}:{}}:void 0;try{let e;try{e=await i(t)}catch(n){if(n?.reason!==`update_confirm_required`)throw n;if(!window.confirm(f(a,`${n.message}。\n\n仍然升级?`,`${n.message}.\n\nUpdate anyway?`)))return;e=await i({...t,force:!0})}T.current&&_(e.version)}catch(t){T.current&&x(Sk(t,a,`install`));try{let t=await e();T.current&&s(t)}catch{}}finally{S.current=!1,T.current&&p(!1)}},changeChannel:async e=>{if(!(!n||c||d||g)){++w.current,u(!0),x(``);try{await n(e),window.dispatchEvent(new Event(`pi-update-channel`))}catch(e){T.current&&(u(!1),x(Sk(e,a,`check`)))}}},cancel:async()=>{if(!(!r||C.current||g)){C.current=!0,h(!0),x(``);try{await r(),y(!1),await E()}catch(e){T.current&&x(Sk(e,a,`install`))}finally{C.current=!1,T.current&&h(!1)}}}}}var wk=(0,P.createContext)(null);function Tk({actions:e,children:t}){let n=Ck(e);return(0,F.jsx)(wk.Provider,{value:n,children:t})}function Ek(){return(0,P.useContext)(wk)}function Dk(e){let t=/(?:^| )PiDesktop\/(\d+\.\d+\.\d+(?:-[\w.-]+)?) PiDesktopBuild\/(\d+)(?: |$)/.exec(e);return!t||t[1].length>80||!Number.isSafeInteger(Number(t[2]))?null:{version:t[1],build:Number(t[2]),handoff:Number(t[2])>=14}}var Ok={group:`_group_14gt8_1`,row:`_row_14gt8_8`,details:`_details_14gt8_15`,preference:`_preference_14gt8_17`,title:`_title_14gt8_25`,summary:`_summary_14gt8_31`,note:`_note_14gt8_31`,error:`_error_14gt8_31`,diagnostics:`_diagnostics_14gt8_41`,actions:`_actions_14gt8_51`};function kk(e){let t=Ek();return t?(0,F.jsx)(jk,{...e,controller:t}):(0,F.jsx)(Ak,{...e})}function Ak(e){let t=Ck(e);return(0,F.jsx)(jk,{...e,controller:t})}function jk(e){let t=l(),n=(e,n)=>f(t,e,n),{status:r,checking:i,installing:a,cancelling:o,targetVersion:s,restartTimedOut:c,error:u,check:d,install:p,changeChannel:m,cancel:h}=e.controller,g=Dk(navigator.userAgent),_=!(!r?.latest||r.available||i),v=r?(0,F.jsxs)(F.Fragment,{children:[n(`当前版本`,`Current version`),` `,r.current,r.available&&r.latest?` → ${r.latest}`:_&&(0,F.jsxs)(F.Fragment,{children:[` · `,(0,F.jsx)(`span`,{role:`status`,children:n(`已是最新版本`,`Up to date`)})]})]}):i?n(`正在读取版本…`,`Reading version…`):n(`暂时无法读取版本`,`Version unavailable`),y=!!(g&&r?.desktopShell&&String(g.build)!==r.desktopShell.build)||!!(r?.launcherHandoff?.required||r?.requiresDesktopUpgrade||r?.launcher&&!r.launcher.releaseChannels),b=!!(g||r?.launcher||r?.desktopShell);return(0,F.jsxs)(`section`,{className:Ok.group,"aria-label":n(`应用更新`,`App updates`),children:[r?.channel&&e.setUpdateChannel&&(0,F.jsxs)(`div`,{className:Ok.preference,children:[(0,F.jsx)(`div`,{className:Ok.title,children:n(`更新偏好`,`Update preference`)}),(0,F.jsx)(vk,{label:n(`更新偏好`,`Update preference`),menuLabel:n(`选择更新偏好`,`Choose update preference`),value:r.channel,disabled:i||a||!!s||c,onChange:e=>{m(e)},options:[{id:`stable`,label:n(`稳定版(推荐)`,`Stable (recommended)`)},{id:`alpha`,label:n(`体验版(包含 alpha)`,`Preview (including alpha)`)}]})]}),r?.channel===`alpha`&&(0,F.jsx)(`p`,{className:Ok.note,children:n(`体验版包含尚在验证的新功能,可能不稳定。`,`Preview releases include features still under testing and may be unstable.`)}),(0,F.jsxs)(`div`,{className:Ok.row,children:[(0,F.jsxs)(`div`,{className:Ok.details,children:[(0,F.jsx)(`div`,{className:Ok.title,children:n(`应用更新`,`App updates`)}),(0,F.jsx)(`p`,{className:Ok.summary,children:v})]}),(0,F.jsxs)(`div`,{className:Ok.actions,children:[r?.available&&r.canRestart&&!s&&!c&&(0,F.jsx)(EO,{variant:`primary`,disabled:a||i,onClick:()=>{p()},children:a?n(`正在安装…`,`Installing…`):r.downgrade?n(`切换到稳定版并重启`,`Switch to stable and restart`):n(`升级并重启`,`Update and restart`)}),(r?.recovery?.canCancel||a)&&e.cancelUpdate&&!s&&(0,F.jsx)(EO,{variant:`outline`,disabled:o,onClick:()=>{h()},children:o?n(`正在取消…`,`Cancelling…`):a?n(`取消下载`,`Cancel download`):n(`取消未完成的升级`,`Cancel unfinished update`)}),(0,F.jsx)(EO,{variant:`outline`,disabled:i||a||!!s,onClick:()=>{d()},children:i?n(`检查中…`,`Checking…`):n(`检查更新`,`Check for updates`)})]})]}),r?.launcherHandoff?.required&&(0,F.jsxs)(`div`,{className:Ok.note,children:[(0,F.jsx)(`p`,{children:n(`安装新版桌面不会自动接管仍在运行的共享后台。需要先安全交接启动器,再使用体验版在线升级。交接会等待聊天空闲、终端关闭和真实图稿保存确认,并保留原本地地址。`,`Installing a desktop update does not take over a running shared backend. Safely hand off the launcher before preview updates. Handoff requires idle chats, closed terminals and real drawing save confirmations, and preserves the local address.`)}),g?.handoff?(0,F.jsx)(`a`,{href:`pi-desktop://launcher-handoff`,target:`_blank`,rel:`noreferrer`,children:n(`安全切换到当前桌面启动器…`,`Safely switch to this desktop launcher…`)}):(0,F.jsxs)(`p`,{children:[n(`安全交接入口从桌面 build 14 开始提供。build 12 已支持体验版,但缺少旧共享后台交接功能;无需重复安装 build 12。`,`The safe handoff action is available from desktop build 14. Build 12 supports preview releases but lacks shared-backend handoff; reinstalling build 12 will not help.`),` `,(0,F.jsx)(`a`,{href:`https://github.com/chengzhiyi/pi-webapp/releases`,target:`_blank`,rel:`noreferrer`,children:n(`下载支持安全交接的桌面版本`,`Get a desktop release with safe handoff`)})]}),!r.launcherHandoff.supported&&(0,F.jsx)(`p`,{children:n(`当前后台还缺少安全交接协议:请先选择稳定版并升级业务包,再从桌面菜单重试交接。`,`This backend lacks the safe handoff protocol: first update its business package on Stable, then retry from the desktop menu.`)})]}),r?.available&&!!r.pluginWarnings?.length&&(0,F.jsxs)(`div`,{className:Ok.note,children:[(0,F.jsx)(`p`,{children:n(`以下插件在新版本中暂时不可用(不影响升级,数据保留):`,`These plugins will be unavailable on the new version (the update is not blocked; their data is kept):`)}),(0,F.jsx)(`ul`,{children:r.pluginWarnings.map(e=>(0,F.jsxs)(`li`,{children:[e.pluginId,`: `,e.message]},e.pluginId))})]}),r?.lastFailure&&!a&&!s&&(0,F.jsxs)(`p`,{className:Ok.note,children:[n(`上次升级到 ${r.lastFailure.version} 未完成,已保留当前版本:`,`The last update to ${r.lastFailure.version} did not complete; the current version was kept: `),r.lastFailure.message]}),r?.reason&&(0,F.jsx)(`p`,{className:Ok.note,children:r.reason}),r?.requiresDesktopUpgrade&&(0,F.jsxs)(`p`,{className:Ok.note,children:[(0,F.jsx)(`a`,{href:`https://github.com/chengzhiyi/pi-webapp/releases`,target:`_blank`,rel:`noreferrer`,children:n(`下载新版桌面应用`,`Download desktop update`)}),n(`。安装支持更新通道的桌面版本后,可在此选择体验版并在线升级。`,`. Install a desktop release with update-channel support, then return here to select preview and update online.`)]}),s&&(0,F.jsx)(`p`,{className:Ok.note,role:`status`,children:n(`正在重启并等待新版连接…`,`Restarting and waiting for the new version…`)}),u&&(0,F.jsx)(`p`,{className:Ok.error,role:`alert`,children:u}),u?.includes(`Missing view flush acknowledgement`)&&(0,F.jsx)(`p`,{className:Ok.note,children:n(`插件视图尚未确认保存。请保存并关闭绘图或编辑器;若视图已失联,请先在插件恢复记录中处理未确认的编辑,再重试升级。`,`A plugin view has not confirmed its save. Save and close drawings or editors; if a view disconnected, review its unconfirmed edits in plugin recovery before retrying.`)}),b&&(0,F.jsxs)(`details`,{className:Ok.diagnostics,open:y,children:[(0,F.jsx)(`summary`,{children:n(`版本详情`,`Version details`)}),g&&(0,F.jsxs)(`p`,{className:Ok.summary,children:[n(`当前桌面窗口`,`Current desktop window`),` `,g.version,` · build `,g.build]}),r?.launcher&&(0,F.jsxs)(`p`,{className:Ok.summary,children:[n(`后台启动器`,`Backend launcher`),` `,r.launcher.version,` · `,n(`体验版持久化`,`Preview persistence`),` `,r.launcher.releaseChannels?n(`支持`,`supported`):n(`不支持`,`unsupported`)]}),r?.desktopShell&&(0,F.jsxs)(`p`,{className:Ok.summary,children:[n(`后台启动时的桌面外壳`,`Desktop shell at backend startup`),` `,r.desktopShell.version,` · build `,r.desktopShell.build]}),r?.desktopShell&&(0,F.jsx)(`p`,{className:Ok.note,children:n(`共享后台可能由旧版桌面启动。当前窗口的桌面版本请查看菜单「pi → 关于 pi」。业务包升级不会替换桌面应用。`,`A shared backend may have been started by an older desktop. For this window’s desktop version, see pi → About pi. Updating the business package does not replace the desktop app.`)})]})]})}var Mk=`https://pi.emath.top`,Nk=`https://github.com/chengzhiyi/pi-webapp/issues`;function Pk(e,t){let n={home:``,quickStart:`getting-started`,troubleshooting:`troubleshooting`}[e];return`${Mk}/${String(t).toLowerCase().startsWith(`zh`)?`zh/`:``}${n}`}function Fk(e){let t=(t,n)=>f(e,t,n);return[{id:`docs`,label:t(`使用文档`,`Documentation`),href:Pk(`home`,e)},{id:`quick-start`,label:t(`快速开始`,`Quick start`),href:Pk(`quickStart`,e)},{id:`troubleshooting`,label:t(`故障排查`,`Troubleshooting`),href:Pk(`troubleshooting`,e)},{id:`issues`,label:t(`在 GitHub 上反馈问题`,`Report an issue on GitHub`),href:Nk}]}var Ik={row:`_row_wp8ea_1`,title:`_title_wp8ea_9`,summary:`_summary_wp8ea_15`,links:`_links_wp8ea_22`};function Lk(){let e=l(),t=(t,n)=>f(e,t,n);return(0,F.jsxs)(`section`,{className:Ik.row,"aria-label":t(`帮助与文档`,`Help & documentation`),children:[(0,F.jsx)(`div`,{className:Ik.title,children:t(`帮助与文档`,`Help & documentation`)}),(0,F.jsx)(`p`,{className:Ik.summary,children:t(`查看使用指南、快速开始和常见问题的解决方法。`,`Read the guides, get started quickly, and find fixes for common problems.`)}),(0,F.jsx)(`ul`,{className:Ik.links,children:Fk(e).map(e=>(0,F.jsx)(`li`,{children:(0,F.jsx)(`a`,{href:e.href,target:`_blank`,rel:`noreferrer`,children:e.label})},e.id))})]})}var Rk={triggerRow:`_triggerRow_f00qz_1`,railRow:`_railRow_f00qz_10`,trigger:`_trigger_f00qz_1`,rail:`_rail_f00qz_10`,triggerLabel:`_triggerLabel_f00qz_54`,overlay:`_overlay_f00qz_61`,mask:`_mask_f00qz_70`,panel:`_panel_f00qz_83`,nav:`_nav_f00qz_105`,navTitle:`_navTitle_f00qz_116`,navList:`_navList_f00qz_125`,navCell:`_navCell_f00qz_133`,active:`_active_f00qz_156`,navIcon:`_navIcon_f00qz_160`,navLabel:`_navLabel_f00qz_164`,content:`_content_f00qz_173`,header:`_header_f00qz_181`,actions:`_actions_f00qz_192`,close:`_close_f00qz_202`,options:`_options_f00qz_82`,hiddenLabel:`_hiddenLabel_f00qz_229`};function zk(e){return e===`general`?(0,F.jsx)(rt,{className:Rk.navIcon,size:16}):e===`models`?(0,F.jsx)(Et,{className:Rk.navIcon,size:16}):e===`packages`?(0,F.jsx)(At,{className:Rk.navIcon,size:16}):e===`plugins`||e===`extensions`?(0,F.jsx)(yt,{className:Rk.navIcon,size:16}):(0,F.jsx)(Ot,{className:Rk.navIcon,size:16})}function Bk({title:e,sections:t,activeId:n,onSelect:r,onClose:i,children:a}){let o=l(),s=(0,P.useId)(),c=(0,P.useRef)(null);return(0,P.useEffect)(()=>{c.current?.focus();let e=e=>{e.key===`Escape`&&!e.defaultPrevented&&!(e.target instanceof Element&&e.target.closest(`[role="menu"]`))&&i()};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[i]),(0,F.jsxs)(`div`,{className:Rk.overlay,role:`presentation`,children:[(0,F.jsx)(`div`,{className:Rk.mask,"aria-hidden":`true`,onClick:i}),(0,F.jsxs)(`div`,{className:Rk.panel,role:`dialog`,"aria-modal":`true`,"aria-labelledby":s,children:[(0,F.jsxs)(`nav`,{className:Rk.nav,"aria-label":o===`zh`?`Pi 设置分类`:`Pi settings sections`,children:[(0,F.jsx)(`div`,{className:Rk.navTitle,id:s,children:e}),(0,F.jsx)(`div`,{className:Rk.navList,children:t.map(e=>(0,F.jsxs)(`button`,{type:`button`,className:`${Rk.navCell} ${n===e.id?Rk.active:``}`,"aria-current":n===e.id?`true`:void 0,onClick:()=>r(e.id),children:[zk(e.id),(0,F.jsx)(`span`,{className:Rk.navLabel,children:e.label})]},e.id))})]}),(0,F.jsxs)(`div`,{className:Rk.content,children:[(0,F.jsxs)(`header`,{className:Rk.header,children:[(0,F.jsx)(`div`,{className:Rk.actions}),(0,F.jsx)(`button`,{ref:c,className:Rk.close,type:`button`,onClick:i,"aria-label":o===`zh`?`关闭 Pi 设置`:`Close Pi settings`,children:(0,F.jsx)(ut,{size:14})})]}),(0,F.jsx)(`div`,{className:Rk.options,children:a})]})]})]})}function Vk(e){return/^(?:npm:|git:|https?:\/\/|ssh:\/\/|git@)/i.test(e.trim())}function Hk(e){let t=l(),n=(e,n)=>f(t,e,n),r=[{kind:`packages`,title:n(`包与扩展`,`Packages & extensions`),hint:n(`包可以包含扩展和技能;本地扩展也可以单独加载。`,`Packages can contain extensions and skills; local extensions can also be loaded separately.`),placeholder:n(`npm 包名、Git 地址或本地目录`,`npm package, Git URL, or local directory`)},{kind:`skills`,title:n(`技能`,`Skills`),hint:n(`Pi 已发现和加载的技能。`,`Skills discovered and loaded by Pi.`),placeholder:n(`SKILL.md 文件或目录路径`,`SKILL.md file or directory path`)}],i=[{id:`general`,label:n(`通用设置`,`General`)},{id:`models`,label:n(`模型`,`Models`)},...r.map(({kind:e,title:t})=>({id:e,label:e===`packages`?n(`包与扩展`,`Packages`):t}))],{onBack:a,getConfig:o,updateConfig:s}=e,[c,u]=(0,P.useState)(null),[d,p]=(0,P.useState)({packages:``,extensions:``,skills:``}),[m,h]=(0,P.useState)(e.setupMode?`models`:`general`),[g,_]=(0,P.useState)(!1),[v,y]=(0,P.useState)(!0),[b,x]=(0,P.useState)(``);(0,P.useEffect)(()=>{e.setupMode&&h(`models`)},[e.setupMode]),(0,P.useEffect)(()=>{let e=!0;return o().then(t=>{e&&u(t)}).catch(t=>{e&&x(t instanceof Error?t.message:n(`无法读取 Pi 设置`,`Could not load Pi settings`))}).finally(()=>{e&&y(!1)}),()=>{e=!1}},[]);let S=async()=>{y(!0),x(``);try{u(await o())}catch(e){x(e instanceof Error?e.message:n(`无法读取 Pi 设置`,`Could not load Pi settings`))}finally{y(!1)}},C=async(e,t,r)=>{_(!0),x(``);try{u(await s(e,`global`,t,r)),t===`add`&&p(t=>({...t,[e]:``}))}catch(e){x(e instanceof Error?e.message:n(`保存失败`,`Save failed`))}finally{_(!1)}},w=r.find(({kind:e})=>e===m),T=w?c?.global[w.kind]??[]:[],E=w?c?.installed?.[w.kind]??[]:[],D=w?d[w.kind].trim():``,O=w?.kind!==`packages`&&Vk(D),k=new Set(c?.installed.packages.map(e=>e.source)??[]),ee=c?.installed.extensions.filter(e=>!k.has(e.source))??[],te=c?.global.packages.filter(e=>!k.has(e))??[],ne=d.extensions.trim(),A=Vk(ne),re=e=>{p(t=>({...t,packages:e})),h(`packages`),x(``)};return(0,F.jsxs)(Bk,{title:n(`Pi 设置`,`Pi Settings`),sections:i,activeId:m,onSelect:e=>{h(e),x(``)},onClose:a,children:[m===`general`&&(0,F.jsxs)(`div`,{className:`pi-settings-content`,children:[(0,F.jsx)(`h2`,{children:n(`通用设置`,`General`)}),(0,F.jsx)(`p`,{className:`pi-settings-intro`,children:n(`调整网页的显示方式。`,`Choose how the web interface appears.`)}),(0,F.jsxs)(`div`,{className:`pi-settings-general`,children:[(0,F.jsx)(xk,{}),(0,F.jsx)(gk,{}),(0,F.jsx)(kk,{getUpdate:e.getUpdate,getRunningVersion:e.getRunningVersion,setUpdateChannel:e.setUpdateChannel,cancelUpdate:e.cancelUpdate,update:e.update}),(0,F.jsx)(Lk,{})]})]}),m===`models`&&(0,F.jsx)(ak,{setupMode:e.setupMode,onReturnToConversation:a,getProviders:e.getProviders,getProviderModels:e.getProviderModels,updateProviderModel:e.updateProviderModel,logoutProvider:e.logoutProvider,addCustomProvider:e.addCustomProvider,startLogin:e.startProviderLogin,getLogin:e.getProviderLogin,getActiveLogin:e.getActiveProviderLogin,respondLogin:e.respondProviderLogin,cancelLogin:e.cancelProviderLogin,refreshModels:e.refreshModels}),w&&(0,F.jsxs)(`div`,{className:`pi-settings-content`,children:[(0,F.jsx)(`h2`,{children:w.title}),(0,F.jsxs)(`p`,{className:`pi-settings-intro`,children:[w.hint,` `,n(`添加或移除后会重新加载 Pi 资源。`,`Pi resources reload after you add or remove one.`)]}),b&&(0,F.jsx)(`p`,{className:`pi-settings-error`,role:`alert`,children:b}),c?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`section`,{className:`pi-settings-section`,"aria-label":`${n(`已发现`,`Discovered `)}${w.title}`,children:[(0,F.jsxs)(`h3`,{children:[w.kind===`packages`?n(`已安装的包`,`Installed packages`):n(`已发现的技能`,`Discovered skills`),` `,(0,F.jsx)(`span`,{children:E.length})]}),(0,F.jsx)(`ul`,{children:E.length?E.map(e=>{let t=w.kind===`packages`?c.installed.extensions.filter(t=>t.source===e.source):[];return(0,F.jsxs)(`li`,{className:`pi-resource-item`,children:[(0,F.jsxs)(`div`,{className:`pi-resource-main`,children:[(0,F.jsx)(`strong`,{title:e.name,children:e.name}),(0,F.jsx)(`small`,{title:e.path||e.source,children:e.path||e.source}),t.length>0&&(0,F.jsxs)(`div`,{className:`pi-package-contents`,children:[(0,F.jsx)(`span`,{children:n(`包含扩展`,`Includes extensions`)}),t.map(e=>(0,F.jsx)(`span`,{title:e.path,children:e.name},e.path))]})]}),(0,F.jsxs)(`div`,{className:`pi-resource-actions`,children:[(0,F.jsxs)(`span`,{className:`pi-resource-meta`,children:[e.enabled?n(`已启用`,`Enabled`):n(`已停用`,`Disabled`),` · `,e.scope===`project`?n(`项目`,`Project`):e.scope===`user`?n(`用户`,`User`):n(`临时`,`Temporary`)]}),w.kind===`packages`&&c.global.packages.includes(e.source)&&(0,F.jsx)(`button`,{type:`button`,disabled:g,onClick:()=>{C(`packages`,`remove`,e.source)},children:n(`移除`,`Remove`)})]})]},`${e.path}:${e.source}`)}):(0,F.jsxs)(`li`,{className:`pi-settings-empty`,children:[n(`未发现`,`No `),w.title]})})]}),w.kind===`packages`&&(0,F.jsxs)(`section`,{className:`pi-settings-section`,"aria-label":n(`独立扩展`,`Standalone extensions`),children:[(0,F.jsxs)(`h3`,{children:[n(`独立扩展`,`Standalone extensions`),` `,(0,F.jsx)(`span`,{children:ee.length})]}),(0,F.jsx)(`ul`,{children:ee.length?ee.map(e=>(0,F.jsxs)(`li`,{className:`pi-resource-item`,children:[(0,F.jsxs)(`div`,{className:`pi-resource-main`,children:[(0,F.jsx)(`strong`,{title:e.name,children:e.name}),(0,F.jsx)(`small`,{title:e.path,children:e.path})]}),(0,F.jsxs)(`span`,{className:`pi-resource-meta`,children:[e.enabled?n(`已启用`,`Enabled`):n(`已停用`,`Disabled`),` · `,e.scope===`project`?n(`项目`,`Project`):e.scope===`user`?n(`用户`,`User`):n(`临时`,`Temporary`)]})]},e.path)):(0,F.jsx)(`li`,{className:`pi-settings-empty`,children:n(`未发现独立扩展`,`No standalone extensions found`)})})]}),(0,F.jsxs)(`section`,{className:`pi-settings-section`,"aria-label":`${n(`手动配置`,`Configure `)}${w.title}`,children:[(0,F.jsx)(`h3`,{children:w.kind===`packages`?n(`添加包`,`Add package`):n(`手动配置技能`,`Configure skills manually`)}),(w.kind===`packages`?te:T).length>0&&(0,F.jsx)(`ul`,{children:(w.kind===`packages`?te:T).map(e=>(0,F.jsxs)(`li`,{className:`pi-config-item`,children:[(0,F.jsxs)(`div`,{className:`pi-resource-main`,children:[(0,F.jsx)(`code`,{title:e,children:e}),w.kind===`packages`&&(0,F.jsx)(`small`,{children:n(`已配置,但未发现安装目录`,`Configured, but installation directory was not found`)}),w.kind!==`packages`&&Vk(e)&&(0,F.jsx)(`small`,{className:`pi-config-warning`,children:n(`未加载:包来源请在“包与扩展”中添加。`,`Not loaded: add package sources under Packages & extensions.`)})]}),(0,F.jsxs)(`div`,{className:`pi-resource-actions`,children:[w.kind!==`packages`&&Vk(e)&&(0,F.jsx)(`button`,{type:`button`,disabled:g,onClick:()=>re(e),children:n(`转到包`,`Go to packages`)}),(0,F.jsx)(`button`,{type:`button`,disabled:g,"aria-label":`${n(`移除`,`Remove`)} ${e}`,onClick:()=>{C(w.kind,`remove`,e)},children:n(`移除`,`Remove`)})]})]},e))}),(0,F.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),D&&!O&&C(w.kind,`add`,D)},children:[(0,F.jsx)(`input`,{"aria-label":`${n(`添加`,`Add `)}${w.title}`,"aria-invalid":O||void 0,"aria-describedby":O?`pi-config-source-help`:void 0,placeholder:w.placeholder,value:d[w.kind],onChange:e=>p(t=>({...t,[w.kind]:e.target.value}))}),(0,F.jsx)(`button`,{type:`submit`,disabled:g||!D||O,children:n(`添加`,`Add`)})]}),O&&(0,F.jsxs)(`p`,{id:`pi-config-source-help`,className:`pi-config-hint`,children:[n(`这是包来源,请在「包」中添加。`,`This is a package source. Add it under Packages.`),(0,F.jsx)(`button`,{type:`button`,onClick:()=>re(D),children:n(`转到包`,`Go to packages`)})]})]}),w.kind===`packages`&&(0,F.jsxs)(`section`,{className:`pi-settings-section`,"aria-label":n(`手动配置扩展路径`,`Configure extension paths manually`),children:[(0,F.jsx)(`h3`,{children:n(`扩展路径`,`Extension paths`)}),c.global.extensions.length>0&&(0,F.jsx)(`ul`,{children:c.global.extensions.map(e=>(0,F.jsxs)(`li`,{className:`pi-config-item`,children:[(0,F.jsxs)(`div`,{className:`pi-resource-main`,children:[(0,F.jsx)(`code`,{title:e,children:e}),Vk(e)&&(0,F.jsx)(`small`,{className:`pi-config-warning`,children:n(`未加载:包来源不能作为扩展路径,请在上方添加包。`,`Not loaded: package sources cannot be extension paths. Add the package above.`)})]}),(0,F.jsxs)(`div`,{className:`pi-resource-actions`,children:[Vk(e)&&(0,F.jsx)(`button`,{type:`button`,disabled:g,onClick:()=>re(e),children:n(`填入包`,`Use as package`)}),(0,F.jsx)(`button`,{type:`button`,disabled:g,onClick:()=>{C(`extensions`,`remove`,e)},children:n(`移除`,`Remove`)})]})]},e))}),(0,F.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),ne&&!A&&C(`extensions`,`add`,ne)},children:[(0,F.jsx)(`input`,{"aria-label":n(`添加扩展路径`,`Add extension path`),"aria-invalid":A||void 0,"aria-describedby":A?`pi-extension-source-help`:void 0,placeholder:n(`扩展文件或目录路径`,`Extension file or directory path`),value:d.extensions,onChange:e=>p(t=>({...t,extensions:e.target.value}))}),(0,F.jsx)(`button`,{type:`submit`,disabled:g||!ne||A,children:n(`添加扩展`,`Add extension`)})]}),A&&(0,F.jsxs)(`p`,{id:`pi-extension-source-help`,className:`pi-config-hint`,children:[n(`这是包来源,请使用上方的“添加包”输入框。`,`This is a package source. Use the Add package field above.`),(0,F.jsx)(`button`,{type:`button`,onClick:()=>re(ne),children:n(`填入包`,`Use as package`)})]})]})]}):v?(0,F.jsx)(`p`,{role:`status`,children:n(`正在读取设置…`,`Loading settings…`)}):(0,F.jsx)(`button`,{className:`pi-settings-retry`,type:`button`,onClick:()=>{S()},children:n(`重试读取设置`,`Retry loading settings`)})]},w.kind)]})}function Uk({size:e=24}){return(0,F.jsxs)(`svg`,{"aria-hidden":`true`,width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,style:{display:`block`,flexShrink:0},children:[(0,F.jsx)(`path`,{d:`m14.5 4.5 5 5M4 20l5.3-1.3L20 8a2.8 2.8 0 0 0-4-4L5.3 14.7 4 20Z`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,F.jsx)(`path`,{d:`m5.5 14.5 4 4M8 15l8-8`,stroke:`currentColor`,strokeWidth:`1.2`,strokeLinecap:`round`})]})}var Wk={page:`_page_1bt34_2`,pageHead:`_pageHead_1bt34_4`,breadcrumb:`_breadcrumb_1bt34_7`,refresh:`_refresh_1bt34_8`,back:`_back_1bt34_8`,danger:`_danger_1bt34_8`,scope:`_scope_1bt34_12`,error:`_error_1bt34_13`,notice:`_notice_1bt34_13`,search:`_search_1bt34_16`,group:`_group_1bt34_17`,cards:`_cards_1bt34_20`,card:`_card_1bt34_20`,artwork:`_artwork_1bt34_23`,cardMain:`_cardMain_1bt34_24`,cardOpen:`_cardOpen_1bt34_25`,dot:`_dot_1bt34_31`,cardEnd:`_cardEnd_1bt34_33`,switch:`_switch_1bt34_34`,thumb:`_thumb_1bt34_36`,detail:`_detail_1bt34_40`,detailHead:`_detailHead_1bt34_41`},Gk={pluginId:`@chengzhiyi/pi-excalidraw`,name:`Excalidraw`,official:!0,icon:`drawing`,installed:!1,enabled:!1,phase:`not-installed`};async function Kk(e,t,n){let r=ve(),{response:i}=await s(`/api/hosted-plugins${e}`,{method:t===void 0?`GET`:`POST`,credentials:`same-origin`,signal:n,headers:{...r?{Authorization:`Bearer ${r}`}:{},...t===void 0?{}:{"Content-Type":`application/json`}},body:t===void 0?void 0:JSON.stringify(t)}),a=await i.json();if(!i.ok)throw Object.assign(Error(a.error?.message??a.error??`Hosted plugin request failed (${i.status})`),{status:i.status,code:a.error?.code??a.errorCode,reason:a.error?.reason??a.reason});return a}var qk={catalog:e=>Kk(``,void 0,e),manage:e=>Kk(`/manage`,e),action:e=>Kk(`/action`,e),decide:(e,t)=>Kk(`/approvals`,{id:e,decision:t}),secret:(e,t,n)=>Kk(`/secrets`,{pluginId:e,name:t,value:n}),signIn:e=>Kk(`/secrets`,e),pendingViews:e=>Kk(`/views`,{operation:`list-pending`,pluginId:e}),view:(e,t)=>Kk(`/views`,e,t)},Jk={section:`_section_1qkpy_1`,attention:`_attention_1qkpy_5`,notice:`_notice_1qkpy_6`,error:`_error_1qkpy_7`,actions:`_actions_1qkpy_8`,configuration:`_configuration_1qkpy_13`,rowActions:`_rowActions_1qkpy_14`};function Yk({pluginId:e,t}){let[n,r]=(0,P.useState)(null),[i,a]=(0,P.useState)(null),[o,s]=(0,P.useState)(``),[c,l]=(0,P.useState)(!1),[u,d]=(0,P.useState)(0);(0,P.useEffect)(()=>{let t=!0;return qk.pendingViews(e).then(e=>{t&&r(e.views)}).catch(e=>{t&&s(String(e))}),()=>{t=!1}},[e,u]);let f=async e=>{l(!0),s(``);try{await qk.view({pluginId:e.pluginId,sessionId:e.sessionId,generation:e.generation,mountId:e.mountId,viewToken:e.viewToken,operation:`discard`,confirmation:`discard-unconfirmed-edits`}),a(null),d(e=>e+1)}catch(e){s(String(e))}finally{l(!1)}};return!n?.length&&!o?null:(0,F.jsxs)(`div`,{className:Jk.error,"data-pending-views":!0,children:[(0,F.jsx)(`p`,{children:t(`宿主仍持有以下视图。若原窗口已关闭,可丢弃该视图后重试;仍打开的窗口请先保存并关闭。丢弃不会保存内容,无法找回的修改可能永久丢失。`,`The host still holds these views. If the original window is closed, discard the view and retry; save and close windows that are still open first. Discarding does not save content; unrecovered edits may be permanently lost.`)}),n?.map(e=>(0,F.jsxs)(`div`,{children:[(0,F.jsxs)(`code`,{children:[e.kind,` · `,e.mountId,` · `,t(`会话`,`session`),` `,e.sessionId,e.dirty||e.busy?` · ${t(`有未确认修改`,`unconfirmed edits`)}`:``]}),` `,i===e.viewToken?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(EO,{variant:`outline`,size:`sm`,disabled:c,onClick:()=>void f(e),children:t(`确认丢弃`,`Confirm discard`)}),` `,(0,F.jsx)(EO,{variant:`outline`,size:`sm`,disabled:c,onClick:()=>a(null),children:t(`取消`,`Cancel`)})]}):(0,F.jsx)(EO,{variant:`outline`,size:`sm`,disabled:c,onClick:()=>a(e.viewToken),children:t(`丢弃此视图`,`Discard this view`)})]},e.viewToken)),o&&(0,F.jsx)(`p`,{role:`alert`,children:o})]})}function Xk({size:e=24}){return(0,F.jsx)(`svg`,{"aria-hidden":`true`,width:e,height:e,viewBox:`0 0 16 16`,fill:`currentColor`,style:{display:`block`,flexShrink:0},children:(0,F.jsx)(`path`,{d:`M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82a7.6 7.6 0 0 1 4 0c1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8Z`})})}function Zk({card:e,size:t=24}){let n=e.icon??(e.pluginId===Gk.pluginId?Gk.icon:void 0);return(0,F.jsx)(n===`drawing`?Uk:n===`github`?Xk:fe,{size:t})}function Qk(e,t,n){let r=(e,n)=>t===`zh`?e:n;return e===`uninstall`?{title:r(`卸载 ${n}?`,`Uninstall ${n}?`),description:r(`保存成功后将关闭相关视图并卸载插件。工作区文件和插件数据会保留,可重新安装后继续使用;保存失败时不会卸载。`,`After saving successfully, related views close and the plugin is uninstalled. Workspace files and plugin data are retained for reinstallation. A failed save stops uninstallation.`),confirm:r(`卸载`,`Uninstall`)}:e===`disable`?{title:r(`停用 ${n}?`,`Disable ${n}?`),description:r(`保存成功后将关闭相关视图并停用插件。插件仍保持安装,工作区文件和插件数据会保留;保存失败时不会停用。`,`After saving successfully, related views close and the plugin is disabled. It remains installed, with workspace files and plugin data retained. A failed save stops disabling.`),confirm:r(`停用`,`Disable`)}:{title:r(`立即更新 ${n} 并重新打开?`,`Update ${n} and reopen now?`),description:r(`全部视图保存成功后将更新插件并重新打开视图,撤销/重做历史会清空。工作区文件和插件数据会保留;保存失败时不会更新。`,`After all views save successfully, update the plugin and reopen its views. Undo/redo history will be cleared. Workspace files and plugin data are retained. A failed save stops the update.`),confirm:r(`更新并重新打开`,`Update and reopen`)}}function $k({card:e,t,onCatalog:n,disabled:r}){let[i,a]=(0,P.useState)({}),[o,s]=(0,P.useState)(``),[c,l]=(0,P.useState)(null),[u,d]=(0,P.useState)(!1),f=(0,P.useRef)(!0);if((0,P.useEffect)(()=>(f.current=!0,()=>{f.current=!1}),[]),(0,P.useEffect)(()=>{if(!c)return;let e=!1;return(async()=>{for(;!e&&f.current;){if(await new Promise(e=>setTimeout(e,3e3)),e||!f.current)return;try{let e=await qk.signIn({auth:`poll`,deviceId:c.deviceId});if(e.status===`granted`&&e.catalog){n(e.catalog),l(null),s(t(`已授权。`,`Authorized.`));return}if(e.status===`denied`||e.status===`expired`){l(null),s(e.status===`denied`?t(`授权已被拒绝。`,`Authorization was denied.`):t(`授权已过期,请重试。`,`Authorization expired. Try again.`));return}}catch(e){l(null),s(e instanceof Error?e.message:String(e));return}}})(),()=>{e=!0}},[c]),!e.secrets?.length)return null;let p=async(r,i)=>{s(``);try{n(await qk.secret(e.pluginId,r,i)),a(e=>({...e,[r]:``})),s(i===null?t(`已移除。`,`Removed.`):t(`已保存。`,`Saved.`))}catch(e){s(e instanceof Error?e.message:String(e))}},m=async t=>{s(``);try{let n=await qk.signIn({auth:`start`,pluginId:e.pluginId,name:t});d(!1),l({name:t,deviceId:n.deviceId,userCode:n.userCode,verificationUri:n.verificationUri})}catch(e){s(e instanceof Error?e.message:String(e))}},h=async e=>{d(await tf(e))},g=e=>{window.open(e.verificationUri,`_blank`,`noopener,noreferrer`),h(e.userCode)},_=()=>{c&&qk.signIn({auth:`cancel`,deviceId:c.deviceId}).catch(()=>{}),l(null)};return(0,F.jsxs)(`section`,{className:Jk.configuration,children:[(0,F.jsx)(`h2`,{children:t(`GitHub 授权`,`GitHub authorization`)}),(0,F.jsx)(`p`,{className:Wk.scope,children:t(`令牌只保存在本机,由主程序代为发起请求;插件进程和页面永远读不到它。`,`The token is stored on this machine and used by the host on the plugin's behalf; plugin code and pages can never read it.`)}),e.secrets.map(e=>(0,F.jsxs)(`div`,{className:Jk.configuration,children:[(0,F.jsxs)(`div`,{className:Jk.actions,children:[(0,F.jsx)(`span`,{role:`status`,children:e.configured?t(`已授权`,`Authorized`):t(`未授权`,`Not authorized`)}),e.signIn===`browser`&&(0,F.jsx)(EO,{variant:`outline`,size:`sm`,disabled:r||!!c,onClick:()=>void m(e.name),children:e.configured?t(`重新授权`,`Re-authorize`):t(`在浏览器中授权 GitHub`,`Authorize with GitHub`)}),e.signIn===`token-page`&&e.createUrl&&(0,F.jsx)(EO,{variant:`outline`,size:`sm`,disabled:r,onClick:()=>window.open(e.createUrl,`_blank`,`noopener,noreferrer`),children:t(`打开 GitHub 创建令牌`,`Open GitHub to create a token`)}),e.configured&&(0,F.jsx)(EO,{variant:`outline`,size:`sm`,disabled:r,onClick:()=>void p(e.name,null),children:t(`移除`,`Remove`)})]}),c?.name===e.name&&(0,F.jsxs)(`div`,{className:Wk.scope,role:`status`,children:[(0,F.jsxs)(`ol`,{style:{margin:0,paddingLeft:20,display:`grid`,gap:10},children:[(0,F.jsxs)(`li`,{children:[t(`复制下面的验证码`,`Copy this code`),(0,F.jsxs)(`div`,{className:Jk.actions,style:{marginTop:6},children:[(0,F.jsx)(`code`,{style:{fontSize:28,letterSpacing:4,fontWeight:600,padding:`6px 14px`,border:`1px solid currentColor`,borderRadius:8,userSelect:`all`},children:c.userCode}),(0,F.jsx)(EO,{variant:`outline`,size:`sm`,onClick:()=>void h(c.userCode),children:u?t(`已复制`,`Copied`):t(`复制`,`Copy`)})]})]}),(0,F.jsxs)(`li`,{children:[t(`打开 GitHub 授权页,粘贴验证码并点击 Authorize`,`Open GitHub, paste the code and click Authorize`),(0,F.jsx)(`div`,{className:Jk.actions,style:{marginTop:6},children:(0,F.jsx)(EO,{size:`sm`,onClick:()=>g(c),children:t(`复制验证码并打开 GitHub`,`Copy code and open GitHub`)})})]})]}),(0,F.jsxs)(`div`,{className:Jk.actions,style:{marginTop:10},children:[(0,F.jsx)(`span`,{children:t(`等待授权中… 完成后这里会自动更新。`,`Waiting for authorization… this updates automatically.`)}),(0,F.jsx)(EO,{variant:`outline`,size:`sm`,onClick:_,children:t(`取消`,`Cancel`)})]})]}),(0,F.jsxs)(`details`,{open:e.signIn===`token-page`&&!e.configured,children:[(0,F.jsx)(`summary`,{children:e.signIn===`token-page`?t(`创建后在此粘贴令牌(仅限目标仓库的 fine-grained token,Issues、Pull requests、Contents 读写)`,`Paste the token here after creating it (fine-grained, limited to the target repository, Issues / Pull requests / Contents read-write)`):t(`改用手动粘贴令牌`,`Paste a token instead`)}),(0,F.jsxs)(`div`,{className:Jk.actions,children:[(0,F.jsx)(`input`,{type:`password`,autoComplete:`off`,"aria-label":e.name,value:i[e.name]??``,onChange:t=>a(n=>({...n,[e.name]:t.target.value}))}),(0,F.jsx)(EO,{variant:`outline`,size:`sm`,disabled:r||!(i[e.name]??``).trim(),onClick:()=>void p(e.name,(i[e.name]??``).trim()),children:t(`保存`,`Save`)})]})]})]},e.name)),o&&(0,F.jsx)(`p`,{role:`status`,className:Wk.scope,children:o})]})}function eA(e,t,n){let r={metadata_not_found:n(`官方插件暂未发布,暂不可安装。稍后可重新检查。`,`The official package is not currently published. Check again later.`),tarball_not_found:n(`发行文件暂不可用。请重新检查或稍后重试。`,`The release file is unavailable. Check again or retry later.`),no_compatible_version:n(`暂无适用于此软件版本的插件。稍后可重新检查。`,`No compatible release for this app version. Check again later.`),registry_unreachable:n(`暂时无法访问下载服务。请检查网络后重试。`,`Cannot reach the download service. Check your network and retry.`),download_cancelled:n(`下载已取消。`,`Download cancelled.`),view_barrier:n(`尚未完成所有视图的保存确认,操作已停止。请先处理本页的刷新前视图记录,并检查仍打开的编辑器,然后重试。`,`Save confirmation is still pending for some views, so the operation stopped. Review previous-view records on this page and any open editors, then retry.`),runtime_owned:n(`插件运行时被其他宿主或遗留锁占用,当前无法打开或卸载。请停止所有宿主并校验备份后,按恢复说明处理;重新安装不会清除此锁。`,`Another host or a retained ownership lock blocks this runtime, including opening and uninstalling. Stop all hosts, verify a backup and follow recovery instructions; reinstalling does not clear the lock.`)}[e.code??``]??n(`操作未完成。请查看诊断信息后重试。`,`Operation did not finish. Review diagnostics and retry.`);return(t&&[`metadata_not_found`,`tarball_not_found`,`no_compatible_version`,`registry_unreachable`,`download_cancelled`].includes(e.code??``)?n(`更新未完成,当前插件及数据已保留。`,`Update did not finish; current plugin and data retained. `):``)+r}function tA({locale:e,generation:t=0,reload:n=0,query:r=``,selectedId:i,visible:a=!0,disabled:o=!1,onSelect:s,onBusyChange:c,onMatchCountChange:l}){let u=(t,n)=>e===`zh`?t:n,[d,f]=(0,P.useState)({plugins:[Gk],offline:!0}),[p,m]=(0,P.useState)(!1),[h,g]=(0,P.useState)(!0),[_,v]=(0,P.useState)(!1),y=(0,P.useRef)(!1),b=(0,P.useRef)(0),x=(0,P.useRef)(new Set);(0,P.useEffect)(()=>{for(let e of d.plugins)e.installed&&x.current.add(e.pluginId)},[d]);let[S,C]=(0,P.useState)(null),[w,T]=(0,P.useState)(null),[E,D]=(0,P.useState)(null),[O,k]=(0,P.useState)(``),[ee,te]=(0,P.useState)(0),[ne,A]=(0,P.useState)(null),re=ne?Qk(ne.operation,e,ne.card.name):null,ie=e=>({message:e instanceof Error?e.message:String(e),code:e?.code});(0,P.useEffect)(()=>{if(y.current)return;let e=++b.current,t=new AbortController;return g(!0),D(null),qk.catalog(t.signal).then(t=>{e===b.current&&(f(t),m(!0),T(null))}).catch(n=>{!t.signal.aborted&&e===b.current&&(T(ie(n)),f(e=>({...e,offline:!0})))}).finally(()=>{e===b.current&&g(!1)}),()=>{t.abort()}},[t,n,ee]);let j=async(e,t,n=!1)=>{if(y.current||o||h)return;y.current=!0,++b.current,A(null);let r=[`install`,`update`,`check`].includes(t)?crypto.randomUUID():void 0;C(r?{pluginId:e.pluginId,id:r}:null),v(!0),c(!0),D(null),k(``);try{let i=await qk.manage({pluginId:e.pluginId,operation:t,...r?{downloadId:r}:{},...n?{reopenEditors:!0}:{}});f(i),m(!0),T(null),k(i.plugins.some(e=>e.pendingVersion)?u(`更新已准备好,关闭编辑器后生效。`,`Update ready. Close editors to apply.`):u(`操作完成。`,`Done.`)),window.dispatchEvent(new Event(`pi:hosted-catalog-changed`))}catch(t){D({id:e.pluginId,problem:ie(t)});try{f(await qk.catalog()),m(!0),window.dispatchEvent(new Event(`pi:hosted-catalog-changed`))}catch{}}finally{y.current=!1,v(!1),c(!1),C(null)}},ae=(e,t)=>{t===`disable`||t===`uninstall`?A({card:e,operation:t}):j(e,t)},oe=d.plugins.some(e=>e.pluginId===Gk.pluginId)?d.plugins:[...d.plugins,Gk],M=oe.find(e=>e.pluginId===i),se=oe.filter(e=>`${e.name} ${e.pluginId} ${le(e)}`.toLowerCase().includes(r.trim().toLowerCase()));(0,P.useEffect)(()=>{l(se.length)},[se.length,l]);let ce=_||h||o||!p||!!d.offline;function le(t){return t.contribution?.entry.description[e]??t.description?.[e]??(t.pluginId===Gk.pluginId?u(`绘制、编辑手绘图表,并将图稿保存到工作区。`,`Draw and edit hand-drawn diagrams, and save them to your workspace.`):u(`按需下载安装的官方插件。`,`An official plugin available on demand.`))}let ue=e=>`${e.name}${e.official?u(`(官方)`,` (Official)`):``}`,de=e=>E?.id===e.pluginId?E.problem:e.error?{code:e.errorCode,message:e.error}:e.updateDiagnostic?.status===`failed`?e.updateDiagnostic:null,fe=e=>p?`${e.installed?u(`已安装`,`Installed`):u(`未安装`,`Not installed`)} · ${e.enabled?u(`已启用`,`Enabled`):u(`未启用`,`Disabled`)}${e.version?` ${e.version}`:``}${e.enabled&&e.phase!==`active`?u(` · 运行时不可用`,` · Runtime unavailable`):``}`:u(`安装状态未知 · 启用状态未知`,`Installation unknown · Enablement unknown`),pe=e=>(0,F.jsx)(`button`,{type:`button`,role:`switch`,className:Wk.switch,"aria-label":u(`启用 ${e.name}`,`Enable ${e.name}`),"aria-checked":p&&e.enabled,disabled:ce||!e.installed,title:p?e.installed?void 0:u(`请先下载插件`,`Download the plugin first`):u(`请先读取插件状态`,`Read plugin status first`),onClick:()=>ae(e,e.enabled?`disable`:`enable`),children:(0,F.jsx)(`span`,{className:Wk.thumb})}),me=e=>{let t=de(e),n=!e.installed&&!!t&&[`metadata_not_found`,`tarball_not_found`,`no_compatible_version`].includes(t.code??``);return(0,F.jsx)(EO,{variant:`outline`,size:`sm`,disabled:ce||n,onClick:()=>ae(e,e.pendingVersion?`retry`:e.installed?`update`:`install`),children:e.pendingVersion?u(`应用待更新版本`,`Apply pending update`):e.installed?u(`更新`,`Update`):n?u(`暂不可下载`,`Unavailable`):e.hasRetainedData||x.current.has(e.pluginId)?u(`重新安装`,`Reinstall`):u(`下载`,`Download`)})};return(0,P.useEffect)(()=>{if(!E||M)return;let e=oe.find(e=>e.pluginId===E.id);zt({key:`hosted-operation-${E.id}`,message:`${e?`${ue(e)}:`:``}${eA(E.problem,!!e?.installed,u)}`,detail:[E.problem.code,E.problem.message].filter(Boolean).join(`: `),detailLabel:u(`诊断信息`,`Diagnostics`)})},[E]),(0,F.jsxs)(`section`,{className:Jk.section,"data-hosted-management":!0,"aria-busy":_||h,style:a?void 0:{display:`none`},children:[!M&&(0,F.jsxs)(`h2`,{children:[u(`官方插件`,`Official plugins`),` `,(0,F.jsx)(`span`,{children:se.length})]}),w&&(0,F.jsxs)(`div`,{role:`alert`,className:Jk.error,children:[u(`无法读取插件状态,请重试。`,`Cannot read plugin status. Please retry.`),(0,F.jsxs)(`details`,{children:[(0,F.jsx)(`summary`,{children:u(`诊断信息`,`Diagnostics`)}),w.message]}),(0,F.jsx)(EO,{variant:`outline`,size:`sm`,disabled:_||h||o,onClick:()=>te(e=>e+1),children:u(`重试`,`Retry`)})]}),d.dev&&(0,F.jsxs)(`div`,{"data-hosted-dev":!0,children:[d.dev.notices.map((e,t)=>(0,F.jsxs)(`div`,{className:e.level===`info`?Jk.notice:Jk.error,role:e.level===`error`?`alert`:`status`,children:[(0,F.jsxs)(`strong`,{children:[u(`开发模式`,`Dev mode`),e.pluginId?` · ${e.pluginId}`:``]}),`: `,e.message]},t)),d.dev.sources.map(e=>(0,F.jsxs)(`p`,{className:Jk.notice,role:`status`,"data-hosted-dev-source":e.pluginId,children:[u(`开发目录`,`Dev directory`),` · `,(0,F.jsx)(`code`,{children:e.root}),` · `,e.state,e.version?` ${e.version}`:``,e.message?` — ${e.message}`:``]},e.pluginId))]}),O&&(0,F.jsx)(`p`,{className:Jk.notice,role:`status`,children:O}),S&&(0,F.jsx)(EO,{variant:`outline`,onClick:()=>{qk.manage({pluginId:S.pluginId,operation:`cancel-download`,downloadId:S.id}).then(()=>k(u(`已请求取消,已完成的安装不会回滚。`,`Cancellation requested; committed installations are not rolled back.`))).catch(e=>D({id:S.pluginId,problem:ie(e)}))},children:u(`取消下载(不回滚已提交安装)`,`Cancel download (no rollback after commit)`)}),M?(0,F.jsxs)(`div`,{className:Wk.detail,"data-hosted-detail":M.pluginId,children:[(0,F.jsxs)(`div`,{className:Wk.detailHead,children:[(0,F.jsx)(`span`,{className:Wk.artwork,"aria-hidden":`true`,children:(0,F.jsx)(Zk,{card:M,size:30})}),(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`strong`,{children:ue(M)}),(0,F.jsx)(`p`,{children:le(M)})]}),pe(M)]}),(0,F.jsxs)(`dl`,{children:[(0,F.jsx)(`dt`,{children:u(`插件标识`,`Plugin ID`)}),(0,F.jsx)(`dd`,{children:(0,F.jsx)(`code`,{children:M.pluginId})}),(0,F.jsx)(`dt`,{children:u(`来源`,`Source`)}),(0,F.jsx)(`dd`,{children:u(`按需下载的官方插件`,`Official on-demand package`)}),(0,F.jsx)(`dt`,{children:u(`状态`,`Status`)}),(0,F.jsx)(`dd`,{children:fe(M)}),M.availableVersion&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`dt`,{children:u(`可用版本`,`Available release`)}),(0,F.jsx)(`dd`,{children:M.availableVersion})]}),M.pendingVersion&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`dt`,{children:u(`待更新版本`,`Pending release`)}),(0,F.jsx)(`dd`,{children:M.pendingVersion})]})]}),((e,t)=>{let n=de(e),r=e.updateDiagnostic;return n?(0,F.jsxs)(`div`,{className:Jk.error,role:`alert`,children:[eA(n,e.installed,u),(0,F.jsxs)(`details`,{children:[(0,F.jsx)(`summary`,{children:u(`诊断信息`,`Diagnostics`)}),(0,F.jsx)(`code`,{children:n.code}),(0,F.jsx)(`p`,{children:n.message}),r&&(0,F.jsxs)(`p`,{children:[r.checkedAt,` · `,r.hostVersion]}),/lock|owned/i.test(n.message)&&(0,F.jsx)(`p`,{children:u(`停止所有程序并备份后,按 docs/hosted-update-recovery.md 恢复。此页面不会清锁。`,`Stop all hosts and back up data before following docs/hosted-update-recovery.md. This page never clears locks.`)})]}),n.code===`view_barrier`&&(0,F.jsx)(Yk,{pluginId:e.pluginId,t:u})]}):null})(M,!0),(0,F.jsx)($k,{card:M,t:u,disabled:ce,onCatalog:e=>{f(e),window.dispatchEvent(new Event(`pi:hosted-catalog-changed`))}}),(0,F.jsxs)(`section`,{className:Jk.configuration,children:[(0,F.jsx)(`h2`,{children:u(`配置与更新`,`Configuration & updates`)}),(0,F.jsx)(`p`,{className:Wk.scope,children:M.icon===`drawing`||M.pluginId===Gk.pluginId?u(`无需额外配置。启用后,可从工作区侧栏打开,也可查看对话中的图稿。图稿保存在工作区,停用或卸载不会删除文件和插件数据。`,`No additional configuration is required. Once enabled, open it from the workspace sidebar or view diagrams in conversations. Disabling or uninstalling retains workspace files and plugin data.`):u(`启用后从工作区侧栏打开。停用或卸载不会删除插件数据。`,`Once enabled, open it from the workspace sidebar. Disabling or uninstalling retains plugin data.`)}),(0,F.jsx)(`p`,{className:Wk.scope,children:u(`兼容的插件可独立更新;软件升级仅在协议不兼容时协调插件版本。`,`Compatible plugins update independently. App upgrades coordinate plugins only when their protocol is incompatible.`)}),(0,F.jsx)(`p`,{className:Wk.scope,children:u(`停用或卸载前会先保存并关闭相关视图;保存失败时不会继续。`,`Disabling or uninstalling first saves and closes related views; a failed save stops the operation.`)}),M.pendingVersion&&(0,F.jsxs)(`p`,{className:Wk.scope,role:`status`,children:[u(`关闭编辑器后更新至:`,`Close editors to update to: `),M.pendingVersion]}),!de(M)&&M.updateDiagnostic?.status===`up-to-date`&&!M.pendingVersion&&(0,F.jsx)(`p`,{className:Wk.scope,children:u(`兼容版本检查已完成。`,`Compatible release check complete.`)}),(0,F.jsxs)(`div`,{className:Jk.actions,children:[me(M),(0,F.jsx)(EO,{variant:`outline`,size:`sm`,disabled:ce,onClick:()=>ae(M,`check`),children:u(`检查更新`,`Check updates`)}),M.installed&&(0,F.jsx)(EO,{variant:`outline`,size:`sm`,disabled:ce,onClick:()=>ae(M,`uninstall`),children:u(`卸载`,`Uninstall`)}),M.pendingVersion&&(0,F.jsx)(EO,{variant:`outline`,size:`sm`,disabled:ce,onClick:()=>A({card:M,operation:`update`,reopen:!0}),children:u(`立即更新并重新打开`,`Update and reopen now`)})]})]})]}):(0,F.jsx)(`ul`,{className:Wk.cards,children:se.map(e=>(0,F.jsxs)(`li`,{className:Wk.card,"data-hosted-card":e.pluginId,children:[(0,F.jsx)(`span`,{className:Wk.artwork,"aria-hidden":`true`,children:(0,F.jsx)(Zk,{card:e,size:30})}),(0,F.jsxs)(`div`,{className:Wk.cardMain,children:[(0,F.jsx)(`button`,{className:Wk.cardOpen,type:`button`,onClick:()=>s({id:e.pluginId,name:e.name}),children:ue(e)}),(0,F.jsx)(`p`,{children:le(e)}),(0,F.jsxs)(`small`,{children:[(0,F.jsx)(`span`,{className:Wk.dot,"data-enabled":p&&e.enabled}),_?u(`正在应用…`,`Applying…`):fe(e),!_&&de(e)&&(0,F.jsx)(`span`,{className:Jk.attention,children:u(` · 需要处理`,` · Needs attention`)})]}),e.pendingVersion?(0,F.jsxs)(`small`,{children:[u(`关闭编辑器后更新至:`,`Close editors to update to: `),e.pendingVersion]}):e.availableVersion&&e.availableVersion!==e.version&&(0,F.jsxs)(`small`,{children:[u(`可用版本:`,`Available release: `),e.availableVersion]})]}),(0,F.jsxs)(`div`,{className:`${Wk.cardEnd} ${Jk.rowActions}`,children:[me(e),pe(e),(0,F.jsx)(`span`,{"aria-hidden":`true`,children:`›`})]})]},e.pluginId))}),(0,F.jsx)(OO,{open:ne!==null,onClose:()=>A(null),title:re?.title??``,closeLabel:u(`关闭`,`Close`),description:re?.description,footer:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(EO,{variant:`outline`,onClick:()=>A(null),children:u(`取消`,`Cancel`)}),(0,F.jsx)(EO,{variant:`primary`,disabled:ce,onClick:()=>{ne&&j(ne.card,ne.operation,ne.reopen)},children:re?.confirm})]})})]})}function nA({getPluginManagement:e,togglePlugin:t,generation:n=0,recovery:r}){let i=l(),a=(e,t)=>f(i,e,t),o=e=>typeof e==`string`?e:e[i],[s,c]=(0,P.useState)(null),[u,p]=(0,P.useState)(null),[m,h]=(0,P.useState)(null),[g,v]=(0,P.useState)(!1),[y,b]=(0,P.useState)(1),[x,S]=(0,P.useState)(0),[C,w]=(0,P.useState)(``),[T,E]=(0,P.useState)(null),[D,O]=(0,P.useState)(!0),[k,ee]=(0,P.useState)(``),[te,ne]=(0,P.useState)(``),[A,re]=(0,P.useState)(null),ie=(0,P.useRef)(!1),j=(0,P.useRef)(!1),ae=(0,P.useRef)(n),oe=(0,P.useRef)(!0),M=async(t=!0)=>{if(ie.current)j.current=!0;else{ie.current=!0,O(!0),t&&(ee(``),S(e=>e+1));try{let t=await e();oe.current&&c(t)}catch(e){oe.current&&ee(e instanceof Error?e.message:a(`无法读取插件`,`Could not load plugins`))}finally{ie.current=!1,oe.current&&O(!1),j.current&&oe.current&&(j.current=!1,M(!1))}}};(0,P.useEffect)(()=>(oe.current=!0,M(),()=>{oe.current=!1}),[]),(0,P.useEffect)(()=>{ae.current!==n&&(ae.current=n,M(!1))},[n]);let se=async e=>{if(s&&!ie.current){ie.current=!0,E(e.id),ee(``),ne(``),re(null);try{let n=await t({id:e.id,enabled:!e.enabled,expected:s.revision});oe.current&&(c(n),ne(a(`插件配置已保存并生效`,`Plugin settings saved and applied`)))}catch(e){oe.current&&ee((e instanceof Error?e.message:a(`保存失败`,`Could not save`))+a(`。请刷新确认状态;操作不会自动重试。`,`. Refresh to verify the state; this operation is not retried automatically.`))}finally{ie.current=!1,oe.current&&E(null),j.current&&oe.current&&(j.current=!1,M(!1))}}},le=e=>{e.id===d.terminal&&e.enabled?re(e):se(e)},ue=e=>(0,F.jsx)(`button`,{type:`button`,role:`switch`,className:Wk.switch,"aria-label":a(`启用 ${o(e.name)}`,`Enable ${o(e.name)}`),"aria-checked":e.enabled,disabled:D||T!==null||g||!e.managed,title:e.managed?void 0:a(`请在包与扩展中管理 Pi 运行时`,`Manage the Pi runtime under Packages & extensions`),onClick:()=>le(e),children:(0,F.jsx)(`span`,{className:Wk.thumb})}),de=e=>e.id===d.git?(0,F.jsx)(ce,{size:30}):e.id===d.terminal?(0,F.jsx)(`span`,{children:`›_`}):e.id===d.files?(0,F.jsx)(_,{kind:`folder`,size:30}):e.id===d.diagrams?(0,F.jsx)(Uk,{size:30}):(0,F.jsx)(`span`,{children:`◇`}),fe=s?.items.find(e=>e.id===u),pe=s?.items.filter(e=>`${o(e.name)} ${o(e.description)} ${e.id}`.toLowerCase().includes(C.trim().toLowerCase()))??[];return(0,F.jsxs)(`section`,{className:Wk.page,"data-plugin-panel":!0,"aria-busy":D||T!==null,children:[(0,F.jsxs)(`header`,{className:Wk.pageHead,children:[(0,F.jsxs)(`div`,{children:[(fe||m)&&(0,F.jsx)(`div`,{className:Wk.breadcrumb,children:(0,F.jsx)(`button`,{type:`button`,onClick:()=>{p(null),h(null)},children:a(`‹ 插件`,`‹ Plugins`)})}),(0,F.jsx)(`h1`,{children:fe?o(fe.name):m?.name??a(`插件`,`Plugins`)}),(0,F.jsx)(`p`,{children:a(`管理此服务的可选能力,按需启用。`,`Manage optional capabilities on this service.`)})]}),(0,F.jsx)(`button`,{type:`button`,className:Wk.refresh,disabled:D||T!==null||g,onClick:()=>void M(),"aria-label":a(`刷新插件`,`Refresh plugins`),children:D?`…`:`↻`})]}),(0,F.jsx)(`p`,{className:Wk.scope,children:a(`全局设置 · 影响此服务的所有工作区和聊天;所有聊天空闲后才可修改。`,`Global settings · Applies to every workspace and chat on this service. Changes require all chats to be idle.`)}),r,k&&(0,F.jsx)(`p`,{className:Wk.error,role:`alert`,children:k}),te&&(0,F.jsx)(`p`,{className:Wk.notice,role:`status`,children:te}),D&&!s&&(0,F.jsx)(`p`,{role:`status`,children:a(`正在读取插件…`,`Loading plugins…`)}),!s&&!D&&(0,F.jsx)(`button`,{type:`button`,className:Wk.back,onClick:()=>void M(),children:a(`重试`,`Retry`)}),fe?(0,F.jsxs)(`div`,{className:Wk.detail,children:[(0,F.jsxs)(`div`,{className:Wk.detailHead,children:[(0,F.jsx)(`span`,{className:Wk.artwork,"aria-hidden":`true`,children:de(fe)}),(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`strong`,{children:o(fe.name)}),(0,F.jsx)(`p`,{children:o(fe.description)})]}),ue(fe)]}),(0,F.jsxs)(`dl`,{children:[(0,F.jsx)(`dt`,{children:a(`插件标识`,`Plugin ID`)}),(0,F.jsx)(`dd`,{children:(0,F.jsx)(`code`,{children:fe.id})}),(0,F.jsx)(`dt`,{children:a(`来源`,`Source`)}),(0,F.jsx)(`dd`,{children:fe.kind===`builtin`?a(`随应用内置`,`Bundled with the application`):a(`Pi 软件包`,`Pi package`)}),(0,F.jsx)(`dt`,{children:a(`状态`,`Status`)}),(0,F.jsx)(`dd`,{children:fe.enabled?a(`已启用`,`Enabled`):a(`已停用`,`Disabled`)}),fe.version&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`dt`,{children:a(`契约版本`,`Contract version`)}),(0,F.jsx)(`dd`,{children:fe.version})]})]}),(0,F.jsx)(`p`,{className:Wk.scope,children:fe.managed?a(`停用会移除入口、关闭相关标签并阻止该插件的后端请求。不会删除工作区文件或聊天记录。`,`Disabling removes entries, closes related tabs and blocks backend requests. Workspace files and chat history are not deleted.`):a(`此插件的 Pi 运行时由软件包管理。当前协议未提供独立、安全卸载该运行时的能力,因此这里仅展示状态,不提供假开关。`,`The Pi package owns this runtime. Its protocol does not expose independent safe teardown, so this page shows its status without a misleading toggle.`)}),fe.id===d.git&&(0,F.jsx)(`p`,{className:Wk.scope,children:a(`关闭 Git 面板不禁止 Agent 或其他终端执行系统 git。`,`Disabling the Git panel does not prevent an agent or another terminal from running system git.`)})]}):s&&!m&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`input`,{type:`search`,className:Wk.search,value:C,onChange:e=>w(e.target.value),placeholder:a(`搜索插件`,`Search plugins`),"aria-label":a(`搜索插件`,`Search plugins`)}),[`builtin`,`external`].map(e=>{let t=pe.filter(t=>t.kind===e);return t.length?(0,F.jsxs)(`section`,{className:Wk.group,children:[(0,F.jsxs)(`h2`,{children:[e===`builtin`?a(`内置能力`,`Built-in capabilities`):a(`已安装的 Web 插件`,`Installed Web plugins`),` `,(0,F.jsx)(`span`,{children:t.length})]}),(0,F.jsx)(`ul`,{className:Wk.cards,children:t.map(e=>(0,F.jsxs)(`li`,{className:Wk.card,"data-plugin-package":e.id,children:[(0,F.jsx)(`span`,{className:Wk.artwork,"aria-hidden":`true`,children:de(e)}),(0,F.jsxs)(`div`,{className:Wk.cardMain,children:[(0,F.jsx)(`button`,{className:Wk.cardOpen,type:`button`,onClick:()=>p(e.id),children:o(e.name)}),(0,F.jsx)(`p`,{children:o(e.description)}),(0,F.jsxs)(`small`,{children:[(0,F.jsx)(`span`,{className:Wk.dot,"data-enabled":e.enabled}),T===e.id?a(`正在应用…`,`Applying…`):e.enabled?a(`已启用`,`Enabled`):a(`已停用`,`Disabled`)]})]}),(0,F.jsxs)(`div`,{className:Wk.cardEnd,children:[ue(e),(0,F.jsx)(`span`,{"aria-hidden":`true`,children:`›`})]})]},e.id))})]},e):null}),!pe.length&&!y&&(0,F.jsx)(`p`,{className:Wk.scope,children:a(`没有匹配的插件`,`No matching plugins`)})]}),(0,F.jsx)(tA,{locale:i,generation:n,reload:x,query:C,selectedId:m?.id??null,visible:!fe,disabled:D||T!==null,onSelect:h,onBusyChange:v,onMatchCountChange:b}),(0,F.jsx)(OO,{open:A!==null,onClose:()=>re(null),title:a(`停用终端?`,`Disable Terminal?`),closeLabel:a(`关闭`,`Close`),description:a(`这会结束此服务所有聊天中的终端进程。未保存的 shell 工作可能丢失。`,`This ends terminal processes in every chat on this service. Unsaved shell work may be lost.`),footer:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`button`,{className:Wk.back,type:`button`,onClick:()=>re(null),children:a(`取消`,`Cancel`)}),(0,F.jsx)(`button`,{className:Wk.danger,type:`button`,onClick:()=>{A&&se(A)},children:a(`停用并结束终端`,`Disable and stop terminals`)})]})})]})}var rA={root:`_root_1ikfi_1`,trigger:`_trigger_1ikfi_2`,glyph:`_glyph_1ikfi_4`,dot:`_dot_1ikfi_5`,srOnly:`_srOnly_1ikfi_6`};function iA(e){let t=Ek();return t?(0,F.jsx)(oA,{...e,controller:t}):(0,F.jsx)(aA,{...e})}function aA(e){let t=Ck(e);return(0,F.jsx)(oA,{...e,controller:t})}function oA({wide:e,hideError:t,controller:n}){let r=l(),i=(e,t)=>f(r,e,t),{status:a,checking:o,installing:s,targetVersion:c,restartTimedOut:u,error:d,install:p}=n;if(Vt(`app-update`,t?null:d&&i(`升级未完成,当前版本和数据已保留。可稍后重试。`,`Update did not finish; the current version and data are retained. You can retry.`),d??void 0,i(`诊断信息`,`Diagnostics`)),!a?.available||!a.canRestart)return null;let m=s?i(`正在升级…`,`Updating…`):c?i(`正在重启…`,`Restarting…`):a.downgrade?i(`切换到稳定版`,`Switch to stable`):i(`下载升级`,`Download updates`),h=a.downgrade?i(`按更新偏好切换到稳定版,需要确认后重启`,`Switch to stable based on your preference; confirmation and restart required`):i(`下载并升级到新版本,服务将短暂重启`,`Download and update to the new version; the service will briefly restart`);return(0,F.jsxs)(`div`,{className:rA.root,children:[(0,F.jsx)(`div`,{className:`pi-settings-trigger-row ${e?``:`pi-settings-trigger-rail`}`,children:(0,F.jsx)(Xe,{label:h,children:(0,F.jsxs)(`button`,{className:`pi-settings-sidebar ${rA.trigger}`,"data-wide":e,type:`button`,"aria-label":m,disabled:o||s||!!c||u,onClick:()=>{p()},children:[(0,F.jsxs)(`span`,{className:rA.glyph,children:[(0,F.jsx)(_t,{size:e?16:18}),(0,F.jsx)(`span`,{className:rA.dot})]}),e&&(0,F.jsx)(`span`,{children:m})]})})}),(s||c)&&(0,F.jsx)(`span`,{className:rA.srOnly,role:`status`,children:m})]})}var sA={trigger:`_trigger_1s641_2`,item:`_item_1s641_3`};function cA({wide:e}){let t=l(),n=((e,n)=>f(t,e,n))(`帮助与文档`,`Help & documentation`),r=(0,P.useRef)(null),i=(0,P.useRef)(null),[a,o]=(0,P.useState)(!1),[s,c]=(0,P.useState)({top:0,left:0}),u=(e=!0)=>{o(!1),e&&r.current?.focus()};return(0,P.useLayoutEffect)(()=>{if(!a)return;let t=r.current.getBoundingClientRect(),{height:n,width:s}=i.current.getBoundingClientRect();c({top:Math.max(12,t.top-n-4),left:Math.max(12,Math.min(e?t.right-s:t.left,window.innerWidth-s-12))}),i.current?.querySelector(`a`)?.focus();let l=e=>{!i.current?.contains(e.target)&&!r.current?.contains(e.target)&&o(!1)},u=()=>{o(!1),r.current?.focus()};return document.addEventListener(`pointerdown`,l,!0),window.addEventListener(`resize`,u),()=>{document.removeEventListener(`pointerdown`,l,!0),window.removeEventListener(`resize`,u)}},[a,e]),(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(Xe,{label:n,disabled:a,children:(0,F.jsx)(`button`,{ref:r,type:`button`,className:`pi-settings-sidebar ${sA.trigger}`,"data-wide":e,"aria-label":n,"aria-haspopup":`menu`,"aria-expanded":a,onClick:()=>a?u():o(!0),onKeyDown:e=>{(e.key===`ArrowDown`||e.key===`ArrowUp`)&&(e.preventDefault(),o(!0))},children:(0,F.jsx)(kt,{size:e?16:18})})}),a&&(0,jt.createPortal)((0,F.jsx)(kp,{ref:i,role:`menu`,tabIndex:-1,"aria-label":n,className:kO.menu,style:s,onKeyDown:e=>{if(e.key===`Escape`)e.preventDefault(),e.stopPropagation(),u();else if(e.key===`Tab`)u();else if([`ArrowDown`,`ArrowUp`,`Home`,`End`].includes(e.key)){e.preventDefault();let t=[...i.current?.querySelectorAll(`a`)??[]],n=t.indexOf(document.activeElement);t[e.key===`Home`?0:e.key===`End`?t.length-1:e.key===`ArrowDown`?(n+1)%t.length:(n-1+t.length)%t.length]?.focus()}},children:Fk(t).map(e=>(0,F.jsx)(`a`,{role:`menuitem`,href:e.href,target:`_blank`,rel:`noreferrer`,className:`${kO.menuItem} ${kO.menuItemNeutral} ${sA.item}`,onClick:()=>u(!1),children:e.label},e.id))}),document.body)]})}var lA=e=>typeof e==`object`&&!!e&&!Array.isArray(e),uA=e=>typeof e==`string`,dA=e=>typeof e==`boolean`,fA=e=>typeof e==`number`&&Number.isFinite(e),pA=e=>t=>t===null||e(t),mA=e=>t=>Array.isArray(t)&&t.every(e),hA=(e,t,n)=>e[t]===void 0||n(e[t]),gA=(e,t)=>t.every(t=>uA(e[t])),_A=(e,t)=>t.every(t=>hA(e,t,uA));function vA(e){return lA(e)&&gA(e,[`id`,`timestamp`])&&[`user`,`assistant`,`tool`,`notice`].includes(e.role)&&mA(e=>lA(e)&&[`text`,`thinking`,`image`,`toolCall`].includes(e.kind)&&uA(e.text)&&_A(e,[`toolName`,`toolCallId`]))(e.blocks)&&_A(e,[`toolName`,`toolCallId`,`model`,`error`])&&hA(e,`isError`,dA)&&hA(e,`usage`,e=>lA(e)&&[`input`,`output`,`cacheRead`,`cacheWrite`,`totalTokens`,`cost`].every(t=>fA(e[t]))&&hA(e,`reasoning`,fA))}function yA(e){return lA(e)&&e.schemaVersion===1&&gA(e,[`sessionId`,`cwd`,`name`])&&pA(uA)(e.model)&&pA(uA)(e.thinkingLevel)&&mA(uA)(e.thinkingLevels)&&dA(e.idle)&&hA(e,`paused`,dA)&&hA(e,`hasPendingPrompts`,dA)&&hA(e,`promptQueue`,e=>lA(e)&&mA(uA)(e.steering)&&mA(uA)(e.followUp))&&hA(e,`queuedPrompts`,mA(e=>lA(e)&&gA(e,[`id`,`text`])&&Number.isSafeInteger(e.revision)&&e.revision>0&&[`queued`,`sending`].includes(e.status)&&hA(e,`error`,uA)&&mA(e=>lA(e)&&uA(e.name)&&dA(e.image))(e.attachments)))&&pA(e=>lA(e)&&pA(fA)(e.tokens)&&fA(e.contextWindow)&&pA(fA)(e.percent))(e.contextUsage)&&mA(vA)(e.messages)&&mA(e=>lA(e)&&gA(e,[`id`,`pluginId`,`kind`,`timestamp`])&&hA(e,`afterMessageId`,uA))(e.pluginEntries)&&hA(e,`interactions`,mA(e=>lA(e)&&gA(e,[`requestId`,`sessionId`,`pluginId`,`kind`])))&&hA(e,`streaming`,pA(vA))}function bA(e){return lA(e)&&pA(uA)(e.activeId)&&mA(e=>lA(e)&&gA(e,[`id`,`path`,`title`])&&hA(e,`available`,dA))(e.items)&&mA(e=>lA(e)&&gA(e,[`id`,`workspaceId`,`name`,`modified`])&&pA(uA)(e.path)&&hA(e,`idle`,dA))(e.sessions)}function xA(e){return lA(e)&&e.type===`error`&&uA(e.message)&&_A(e,[`errorCode`,`errorId`,`requestId`,`operationId`])&&hA(e,`errorReported`,dA)}function SA(e){if(!lA(e)||!uA(e.type))throw Error(`Invalid stream event`);switch(e.type){case`snapshot`:if(lA(e.session)&&e.session.schemaVersion!==1)throw Error(`Unsupported session schema`);if(yA(e.session))return{type:`snapshot`,session:e.session};throw Error(`Invalid session snapshot`);case`stream`:if(e.message===null||vA(e.message))return{type:`stream`,message:e.message};break;case`workspaces`:if(bA(e.value))return{type:`workspaces`,value:e.value};break;case`shutdown`:if(hA(e,`reconnect`,dA))return{type:`shutdown`,...e.reconnect===void 0?{}:{reconnect:e.reconnect}};break;case`plugins_changed`:return{type:`plugins_changed`};case`hosted_plugins_changed`:return{type:`hosted_plugins_changed`};case`plugin_state`:if(Array.isArray(e.disabled)&&e.disabled.every(e=>typeof e==`string`&&e.length<=200))return{type:`plugin_state`,disabled:e.disabled};break;case`error`:if(xA(e))return e;break;default:throw Error(`Unsupported stream event`)}throw Error(`Invalid stream event`)}var CA=ve();async function wA(e,n,r){return t(await s(e,{method:`POST`,headers:{Authorization:`Bearer ${CA}`,"Content-Type":`application/json`},body:JSON.stringify(n),signal:r}))}async function TA(e){return t(await s(e,{headers:{Authorization:`Bearer ${CA}`}}))}function EA(){let e=l(),[n,i]=(0,P.useState)(null),[a,o]=(0,P.useState)(null),[c,u]=(0,P.useState)(CA?`connecting`:`missing-token`),[d,f]=(0,P.useState)(``),[p,m]=(0,P.useState)([]),[h,g]=(0,P.useState)(`loading`),[_,v]=(0,P.useState)([]),[y,b]=(0,P.useState)({items:[],activeId:null,sessions:[]}),[x,S]=(0,P.useState)(null),[C,w]=(0,P.useState)([]),[T,E]=(0,P.useState)(0);return(0,P.useEffect)(()=>{if(!CA)return;let e=new AbortController,n,a=!0,c=!1;return(async()=>{for(;a;){let l,d,p=`stream_connect`;try{u(`connecting`);let n=await s(`/api/events`,{headers:{Authorization:`Bearer ${CA}`},cache:`no-store`,signal:e.signal}),{response:m}=n;if(d=n.correlation,m.ok||await t(n),!m.body)throw Error(m.status===401?r(`访问令牌无效,请在 Pi 中重新输入 /web。`,`Invalid access token. Run /web again in Pi.`):r(`连接 Pi 失败`,`Could not connect to Pi`));u(`connected`),he({connection:`connected`}),ye(`stream_connected`,{...d}),f(``),l=m.body.getReader();let h=new TextDecoder,g=``;for(;a;){p=`stream_read`;let{done:e,value:t}=await l.read();if(e)break;p=`stream_event`,g+=h.decode(t,{stream:!0});let n=g.indexOf(`
|
|
62
62
|
`);for(;n!==-1;){let e=g.slice(0,n);if(g=g.slice(n+1),e){let t;try{t=SA(JSON.parse(e))}catch(e){let t=e instanceof SyntaxError?Error(`Invalid event JSON`):e;throw _e(t,{...d,stage:`ndjson_parse`}),t}if(t.type===`shutdown`){if(l.cancel().catch(()=>{}),t.reconnect===!0)throw new DOMException(`Pi web service is restarting`,`AbortError`);a=!1,u(`disconnected`),he({connection:`disconnected`}),ye(`bridge_shutdown`),f(r(`Pi 网页服务已关闭,请在 Pi 中重新输入 /web。`,`The Pi web service stopped. Run /web again in Pi.`));return}if(t.type===`snapshot`&&(i(t.session),he({sessionId:t.session.sessionId,idle:t.session.idle,model:t.session.model,thinkingLevel:t.session.thinkingLevel,messageCount:t.session.messages?.length??0}),(t.session.idle||`streaming`in t.session)&&o(t.session.streaming??null)),t.type===`stream`){let e=t.message!==null;e&&f(``),e!==c&&ye(e?`stream_start`:`stream_end`),c=e,o(t.message)}t.type===`workspaces`&&b(t.value),t.type===`error`&&(f(t.message),!t.errorId&&!t.errorReported&&t.errorCode!==`validation_error`&&_e(Error(`Agent response failed`),{stage:`agent`,code:`agent_failed`,requestId:t.requestId,operationId:t.operationId}),ye(`agent_error`,{errorId:t.errorId,requestId:t.requestId,operationId:t.operationId})),t.type===`plugins_changed`&&window.location.reload(),t.type===`hosted_plugins_changed`&&E(e=>e+1),t.type===`plugin_state`&&(w(t.disabled),E(e=>e+1))}n=g.indexOf(`
|
|
63
63
|
`)}}throw p=`stream_end`,Error(r(`Pi 网页连接已关闭`,`The Pi web connection has closed`))}catch(e){if(l?.cancel().catch(()=>{}),!a)return;he({connection:`disconnected`});let t={...d,route:`/api/events`,stage:p,connection:`disconnected`};_e(e,t),ye(`stream_disconnected`,t),u(`disconnected`),g(`loading`),f(e instanceof Error?e.message:r(`连接 Pi 失败`,`Could not connect to Pi`)),await new Promise(e=>{n=setTimeout(e,1500)})}}})(),()=>{a=!1,e.abort(),n&&clearTimeout(n)}},[]),(0,P.useEffect)(()=>{CA||f(r(`请在 Pi 终端输入 /web,打开显示的完整地址。`,`Enter /web in the Pi terminal and open the full address shown.`))},[e]),(0,P.useEffect)(()=>{if(c!==`connected`)return;let e=!0;return g(`loading`),TA(`/api/plugin-management`).then(t=>{e&&w(t.items.filter(e=>!e.enabled).map(e=>e.id))}).catch(()=>{}),TA(`/api/models`).then(t=>{e&&(m(t),g(`ready`))}).catch(t=>{e&&(g(`error`),f(t instanceof Error?t.message:r(`无法获取模型列表`,`Could not load the model list`)))}),TA(`/api/commands`).then(t=>{e&&v(t)}).catch(()=>{e&&v([])}),()=>{e=!1}},[c,n?.sessionId]),(0,P.useEffect)(()=>{if(c!==`connected`)return;let e=!0;return TA(`/api/workspaces`).then(t=>{e&&b(t)}).catch(()=>{}),TA(`/api/directory/capability`).then(t=>{e&&S(t.kind)}).catch(()=>{e&&S(`browse`)}),()=>{e=!1}},[c]),{session:n,streaming:a,connection:c,error:d,models:p,modelsStatus:h,commands:_,workspaces:y,directoryPickerKind:x,async resolvePluginInteraction(e,t,r){if(!n)throw Error(`No active session`);await wA(`/api/plugin-interaction`,{sessionId:n.sessionId,pluginId:e,requestId:t,value:r})},plugins:()=>TA(`/api/plugins`),async invokePluginAction(e,t,i){if(!n||c!==`connected`)throw Error(r(`Pi 会话不可用`,`Pi session is unavailable`));return(await wA(`/api/plugin-action`,{sessionId:n.sessionId,pluginId:e,action:t,input:i})).value},async pickDirectory(){if(!n||c!==`connected`)throw Error(r(`Pi 会话不可用`,`Pi session is unavailable`));return(await wA(`/api/directory/pick`,{sessionId:n.sessionId})).path},async listDirectory(e,t){if(!n||c!==`connected`)throw Error(r(`Pi 会话不可用`,`Pi session is unavailable`));return wA(`/api/directory/list`,{sessionId:n.sessionId,...e===void 0?{}:{path:e}},t)},async createDirectory(e,t){if(!n||c!==`connected`)throw Error(r(`Pi 会话不可用`,`Pi session is unavailable`));return(await wA(`/api/directory/create`,{sessionId:n.sessionId,path:e,name:t})).path},disabledPlugins:C,pluginGeneration:T,getPluginManagement:()=>TA(`/api/plugin-management`),async togglePlugin(e){if(!n||c!==`connected`)throw Error(r(`Pi 会话不可用`,`Pi session is unavailable`));return wA(`/api/plugin-management`,{sessionId:n.sessionId,...e})},clearError:()=>f(``),async upload(e,i){if(!n||c!==`connected`)throw Error(r(`Pi 会话不可用`,`Pi session is unavailable`));let a=`/api/attachment?sessionId=${encodeURIComponent(n.sessionId)}&name=${encodeURIComponent(e.name)}`,o=await s(a,{method:`POST`,headers:{Authorization:`Bearer ${CA}`,"Content-Type":e.type||`application/octet-stream`},body:e,signal:i});if(o.response.status===404)throw Error(r(`当前 Pi 桥接服务仍是旧版。请在 Pi 中输入 /reload,再输入 /web 并打开新地址,然后重试上传。`,`The Pi bridge is outdated. Run /reload, then /web in Pi, open the new address, and retry the upload.`));return await t(o)},async discardAttachment(e){n&&c===`connected`&&await wA(`/api/attachment/remove`,{sessionId:n.sessionId,id:e})},async updateQueuedPrompt(e,t,i){if(!n||c!==`connected`)throw Error(r(`Pi 会话不可用`,`Pi session is unavailable`));await wA(`/api/prompt-queue`,{sessionId:n.sessionId,id:e,revision:t,action:i})},async send(e,t=[],i){if(n&&c===`connected`){f(``);try{await wA(`/api/message`,{sessionId:n.sessionId,text:e,attachments:t,delivery:i})}catch(e){throw f(e instanceof Error?e.message:r(`发送失败`,`Send failed`)),e}}},async loadMessageImage(e,i){if(!n||c!==`connected`)throw Error(r(`Pi 会话不可用`,`Pi session is unavailable`));let a=`/api/image?sessionId=${encodeURIComponent(n.sessionId)}&messageId=${encodeURIComponent(e)}&index=${i}`,o=await s(a,{headers:{Authorization:`Bearer ${CA}`}});o.response.ok||await t(o);try{return await o.response.blob()}catch(e){throw _e(e,{...o.correlation,stage:`image_read`}),e}},async stop(){if(n&&c===`connected`)try{await wA(`/api/abort`,{sessionId:n.sessionId}),f(``)}catch(e){throw f(e instanceof Error?e.message:r(`停止失败`,`Could not stop`)),e}},async resume(){if(!n||c!==`connected`)throw Error(r(`Pi 会话不可用`,`Pi session is unavailable`));f(``);try{await wA(`/api/resume`,{sessionId:n.sessionId})}catch(e){throw f(e instanceof Error?e.message:r(`继续失败`,`Could not continue`)),e}},async compact(){if(!n||c!==`connected`)throw Error(r(`Pi 会话不可用`,`Pi session is unavailable`));try{await wA(`/api/compact`,{sessionId:n.sessionId}),f(``)}catch(e){throw f(e instanceof Error?e.message:r(`压缩失败`,`Compaction failed`)),e}},async newSession(){if(n&&c===`connected`)try{await wA(`/api/new-session`,{sessionId:n.sessionId})}catch(e){throw f(e instanceof Error?e.message:r(`无法创建新会话`,`Could not create a new session`)),e}},async addWorkspace(e,t){if(!n||c!==`connected`)throw Error(r(`Pi 会话不可用`,`Pi session is unavailable`));await wA(`/api/workspace/add`,{sessionId:n.sessionId,path:e,create:t})},async selectWorkspace(e){if(!n||c!==`connected`)throw Error(r(`Pi 会话不可用`,`Pi session is unavailable`));await wA(`/api/workspace/select`,{sessionId:n.sessionId,id:e})},async newSessionInWorkspace(e){if(!n||c!==`connected`)throw Error(r(`Pi 会话不可用`,`Pi session is unavailable`));await wA(`/api/workspace/new-session`,{sessionId:n.sessionId,id:e})},async removeWorkspace(e){if(!n||c!==`connected`)throw Error(r(`Pi 会话不可用`,`Pi session is unavailable`));await wA(`/api/workspace/remove`,{sessionId:n.sessionId,id:e})},async selectSession(e,t,i){if(!n||c!==`connected`)throw Error(r(`Pi 会话不可用`,`Pi session is unavailable`));await wA(`/api/session/select`,{sessionId:n.sessionId,workspaceId:e,id:t,path:i??``})},async renameSession(e,t,i,a){if(!n||c!==`connected`)throw Error(r(`Pi 会话不可用`,`Pi session is unavailable`));await wA(`/api/session/rename`,{sessionId:n.sessionId,workspaceId:e,id:t,path:i??``,name:a})},async deleteSession(e,t,i){if(!n||c!==`connected`)throw Error(r(`Pi 会话不可用`,`Pi session is unavailable`));await wA(`/api/session/delete`,{sessionId:n.sessionId,workspaceId:e,id:t,path:i??``})},async setModel(e,t){if(n&&c===`connected`)try{await wA(`/api/model`,{sessionId:n.sessionId,provider:e,id:t}),f(``)}catch(e){throw f(e instanceof Error?e.message:r(`切换模型失败`,`Could not change model`)),e}},async setThinkingLevel(e){if(n&&c===`connected`)try{await wA(`/api/thinking-level`,{sessionId:n.sessionId,level:e}),f(``)}catch(e){throw f(e instanceof Error?e.message:r(`切换推理强度失败`,`Could not change reasoning effort`)),e}},async getConfig(){return TA(`/api/config`)},async getUpdate(){return TA(`/api/update`)},async getRunningVersion(e){return t(await s(`/api/update/version`,{headers:{Authorization:`Bearer ${CA}`},signal:e},{expectedNetworkFailure:!0}))},async setUpdateChannel(e){if(!n||c!==`connected`)throw Error(r(`Pi 会话不可用`,`Pi session is unavailable`));return wA(`/api/update/channel`,{sessionId:n.sessionId,channel:e})},async cancelUpdate(){if(!n||c!==`connected`)throw Error(r(`Pi 会话不可用`,`Pi session is unavailable`));await wA(`/api/update/cancel`,{sessionId:n.sessionId})},async update(e){if(!n||c!==`connected`)throw Error(r(`Pi 会话不可用`,`Pi session is unavailable`));return wA(`/api/update`,{sessionId:n.sessionId,...e})},async getProviders(){return TA(`/api/providers`)},async getProviderModels(e){return TA(`/api/provider/models?providerId=${encodeURIComponent(e)}`)},async updateProviderModel(e,t){if(!n||c!==`connected`)throw Error(r(`Pi 会话不可用`,`Pi session is unavailable`));await wA(`/api/provider/models`,{sessionId:n.sessionId,providerId:e,change:t});try{m(await TA(`/api/models`)),g(`ready`)}catch{f(r(`模型已保存,但会话模型列表暂时无法刷新。`,`Model saved, but the conversation model list could not refresh.`))}},async logoutProvider(e){if(!n||c!==`connected`)throw Error(r(`Pi 会话不可用`,`Pi session is unavailable`));await wA(`/api/provider/logout`,{sessionId:n.sessionId,providerId:e});try{m(await TA(`/api/models`)),g(`ready`)}catch{f(r(`认证已移除,但会话模型列表暂时无法刷新。`,`Credentials removed, but the conversation model list could not refresh.`))}},async addCustomProvider(e){if(!n||c!==`connected`)throw Error(r(`Pi 会话不可用`,`Pi session is unavailable`));await wA(`/api/provider/custom`,{sessionId:n.sessionId,provider:e})},async startProviderLogin(e,t,i){if(!n||c!==`connected`)throw Error(r(`Pi 会话不可用`,`Pi session is unavailable`));return wA(`/api/provider/login`,{sessionId:n.sessionId,providerId:e,method:t,...i===void 0?{}:{initialSecret:i}})},async getProviderLogin(e){return TA(`/api/provider/login?id=${encodeURIComponent(e)}`)},async getActiveProviderLogin(){return(await TA(`/api/provider/login/active`)).active},async respondProviderLogin(e,t){if(!n||c!==`connected`)throw Error(r(`Pi 会话不可用`,`Pi session is unavailable`));await wA(`/api/provider/login/respond`,{sessionId:n.sessionId,id:e,value:t})},async cancelProviderLogin(e){n&&c===`connected`&&await wA(`/api/provider/login/cancel`,{sessionId:n.sessionId,id:e})},async refreshModels(){m(await TA(`/api/models`)),g(`ready`)},async updateConfig(e,t,i,a){if(!n||c!==`connected`)throw Error(r(`Pi 会话不可用`,`Pi session is unavailable`));return wA(`/api/config`,{sessionId:n.sessionId,kind:e,scope:t,action:i,value:a})}}}var DA=2;function OA(e,t,n){let r=e.position?.start.offset;return r===void 0?-(n+1):t+r}function kA(e,t){for(let n=t;n<e.length;n+=1){let t=e[n];if(t===`
|
|
64
64
|
`)return n+1;if(t===`\r`)return e[n+1]===`
|
|
@@ -497,7 +497,7 @@ l0,-`+(t+144)+`c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7,
|
|
|
497
497
|
`,c]}var fJ=class{labels;parser=new PA(Cj);generation=-1;frozenCount=0;frozenElements=[];frozenTargets=Lq();frozenFootnoteOrder=[];frozenFootnoteCounts=new Map;lastText=null;lastRendered=[];constructor(e){this.labels=e}render(e){if(e===this.lastText)return this.lastRendered;let{frozen:t,tail:n,generation:r}=this.parser.update(e);r!==this.generation&&(this.generation=r,this.frozenCount=0,this.frozenElements=[],this.frozenTargets=Lq(),this.frozenFootnoteOrder=[],this.frozenFootnoteCounts=new Map);let i=t.slice(this.frozenCount);Rq(i.map(e=>e.node),this.frozenTargets);let a={definitions:new Map(this.frozenTargets.definitions),footnotes:new Map(this.frozenTargets.footnotes)};if(Rq(n.map(e=>e.node),a),i.length>0){let e={streaming:!0,labels:this.labels,fileMentions:void 0,pathImages:void 0,targets:a,footnoteOrder:this.frozenFootnoteOrder,footnoteCounts:this.frozenFootnoteCounts},n=[...this.frozenElements];for(let t of zq(i,e))n.length>0&&n.push(`
|
|
498
498
|
`),n.push(t);this.frozenElements=n,this.frozenCount=t.length}let o={streaming:!0,labels:this.labels,fileMentions:void 0,pathImages:void 0,targets:a,footnoteOrder:[...this.frozenFootnoteOrder],footnoteCounts:new Map(this.frozenFootnoteCounts)},s=[...this.frozenElements];for(let e of zq(n,o))s.length>0&&s.push(`
|
|
499
499
|
`),s.push(e);let c=uJ(o);return c!==null&&s.push(`
|
|
500
|
-
`,c),this.lastText=e,this.lastRendered=s,this.lastRendered}},pJ=(0,P.memo)(function({text:e,streaming:t=!1,labels:r,fileMentions:i,pathImages:a,variant:o=`body`}){let s=(0,P.useRef)(null),c=(0,P.useRef)(r),l=(0,P.useMemo)(()=>t?((s.current===null||c.current!==r)&&(s.current=new fJ(r),c.current=r),s.current.render(e)):(s.current=null,dJ(e,r,i,a)),[e,t,r,i,a]);return(0,F.jsx)(`div`,{className:n(Mq.markdown,o===`compact`&&Mq.compact),"data-markdown-variant":o===`compact`?o:void 0,children:l})});function mJ(e,t){throw Error(`${t}: unhandled ${JSON.stringify(e)}`)}function hJ(e,t){let n=e.nodes[t];if(n===void 0)throw Error(`layout: unknown node ${t}`);return n}function gJ(e,t){let n=hJ(e,t);if(n.kind!==`pane`)throw Error(`layout: ${t} is not a pane`);return n}function _J(e,t){let n=hJ(e,t);if(n.kind!==`split`)throw Error(`layout: ${t} is not a split`);return n}function vJ(e,t){let n=e.tabs[t];if(n===void 0)throw Error(`layout: unknown tab ${t}`);return n}function yJ(e){if(e.host!==`float`||e.rect===void 0)throw Error(`layout: ${e.id} is not floating`);return e.rect}function bJ(e,t){let n=e.floats.indexOf(t);if(n<0)throw Error(`layout: floating pane ${t} is not in the z order`);return n}function xJ(e){let t=e.tabs[0];if(t===void 0||e.tabs.length!==1)throw Error(`layout: ${e.id} does not hold exactly one tab`);return t}function SJ(e,t){for(let n of Object.values(e.nodes))if(n.kind===`split`&&n.children.includes(t))return n}function CJ(e,t){for(let n of Object.values(e.nodes))if(n.kind===`pane`&&n.tabs.includes(t))return n;throw Error(`layout: tab ${t} has no pane`)}function wJ(e){let t=[],n=r=>{let i=hJ(e,r);if(i.kind===`pane`)t.push(i.id);else for(let e of i.children)n(e)};return n(e.rootId),t}function TJ(e){let t=e.reduce((e,t)=>e+t,0);if(!(t>0))throw Error(`layout: sizes must sum above zero`);return Math.abs(t-1)<1e-12?[...e]:e.map(e=>e/t)}function EJ(e){return Object.entries(e)}function DJ(e){return Object.keys(e)}function OJ(e,t){let n={};for(let[r,i]of EJ(e.nodes))r in t||(n[r]=i);for(let[e,r]of EJ(t))r!==null&&(n[e]=r);return{...e,nodes:n}}function kJ(e,t){let n={};for(let[r,i]of EJ(e.tabs))r in t||(n[r]=i);for(let[e,r]of EJ(t))r!==null&&(n[e]=r);return{...e,tabs:n}}function AJ(e,t,n){let r=Math.max(0,Math.min(t,e.length));return[...e.slice(0,r),n,...e.slice(r)]}function jJ(e,t){return[...e.slice(0,t),...e.slice(t+1)]}function MJ(e,t){let n=jJ(e,t);if(n.length!==0)return n[Math.max(0,t-1)]}function NJ(e,t,n){return{...e,tabs:t,activeTabId:n}}function PJ(e,t,n){let r=SJ(e,t);if(r===void 0){if(e.rootId!==t)throw Error(`layout: ${t} is neither rooted nor parented`);return{...e,rootId:n}}let i=r.children.map(e=>e===t?n:e);return OJ(e,{[r.id]:{...r,children:i}})}function FJ(e,t){let n=hJ(e,e.rootId);for(;n.kind===`split`;){let r=t(n);if(r===void 0)throw Error(`layout: split ${n.id} has no children`);n=hJ(e,r)}return n.id}function IJ(e){return FJ(e,e=>e.children[0])}function LJ(e){return FJ(e,e=>e.axis===`row`?e.children.at(-1):e.children[0])}function RJ(e,t){let n={};for(let r of t)n[r]=gJ(e,r).activeTabId;return{type:`restoreFocus`,activePaneId:e.activePaneId,floats:e.floats,paneActiveTabs:n}}function zJ(e,t){return[...e.filter(e=>e!==t),t]}function BJ(e,t){return e.activePaneId===t?{...e,activePaneId:IJ(e)}:e}function VJ(e){return{kind:`pane`,id:e,host:`dock`,tabs:[],activeTabId:void 0,rect:void 0}}function HJ(e,t){if(e.nodes[t]!==void 0)throw Error(`layout: node ${t} already exists`)}function UJ(e,t){if(e.tabs[t]!==void 0)throw Error(`layout: tab ${t} already exists`)}function WJ(e,t){if(gJ(e,t.paneId).host!==`dock`)throw Error(`layout: split requires a docked pane`);HJ(e,t.newPaneId);let n=VJ(t.newPaneId),r=SJ(e,t.paneId);if(r!==void 0&&r.axis===t.axis){let i=r.children.indexOf(t.paneId),a=t.direction===`after`?i+1:i,o=AJ(r.children,a,t.newPaneId),s=r.sizes.flatMap((e,t)=>t===i?[e/2,e/2]:[e]);return{state:OJ(e,{[t.newPaneId]:n,[r.id]:{...r,children:o,sizes:s}}),inverse:[{type:`merge`,paneId:t.newPaneId},{type:`resize`,splitId:r.id,sizes:r.sizes}]}}HJ(e,t.newSplitId);let i=PJ(e,t.paneId,t.newSplitId),a=t.direction===`after`?[t.paneId,t.newPaneId]:[t.newPaneId,t.paneId];return{state:OJ(i,{[t.newPaneId]:n,[t.newSplitId]:{kind:`split`,id:t.newSplitId,axis:t.axis,children:a,sizes:[.5,.5]}}),inverse:[{type:`merge`,paneId:t.newPaneId}]}}function GJ(e,t){let n=gJ(e,t.paneId);if(n.tabs.length>0)throw Error(`layout: merge requires an empty pane`);let r=RJ(e,[]);if(n.host===`float`){let i=bJ(e,t.paneId);return{state:BJ(OJ({...e,floats:jJ(e.floats,i)},{[t.paneId]:null}),t.paneId),inverse:[{type:`insertPane`,pane:n,tabs:[],attach:{mode:`float`,index:i}},r]}}let i=SJ(e,t.paneId);if(i===void 0)throw Error(`layout: the docked root pane cannot be merged`);let a=i.children.indexOf(t.paneId);if(i.children.length>2){let o=jJ(i.children,a),s=TJ(jJ(i.sizes,a));return{state:BJ(OJ(e,{[t.paneId]:null,[i.id]:{...i,children:o,sizes:s}}),t.paneId),inverse:[{type:`insertPane`,pane:n,tabs:[],attach:{mode:`child`,parentId:i.id,index:a,sizes:i.sizes}},r]}}let o=i.children[1-a];if(o===void 0)throw Error(`layout: merge found a split without a sibling`);return{state:BJ(OJ(PJ(e,i.id,o),{[t.paneId]:null,[i.id]:null}),t.paneId),inverse:[{type:`insertPane`,pane:n,tabs:[],attach:{mode:`wrap`,targetId:o,split:i}},r]}}function KJ(e,t){let n=gJ(e,t.paneId);if(n.host!==`dock`)throw Error(`layout: openTab requires a docked pane`);UJ(e,t.tab.id);let r=RJ(e,[n.id]);return{state:{...OJ(kJ(e,{[t.tab.id]:t.tab}),{[n.id]:NJ(n,AJ(n.tabs,t.index,t.tab.id),t.tab.id)}),activePaneId:n.id},inverse:[{type:`closeTab`,tabId:t.tab.id},r]}}function qJ(e,t){let n=gJ(e,t.paneId);if(n.host!==`dock`)throw Error(`layout: insertTab requires a docked pane`);UJ(e,t.tab.id);let r=RJ(e,[n.id]),i=AJ(n.tabs,t.index,t.tab.id);return{state:OJ(kJ(e,{[t.tab.id]:t.tab}),{[n.id]:NJ(n,i,n.activeTabId??t.tab.id)}),inverse:[{type:`closeTab`,tabId:t.tab.id},r]}}function JJ(e,t){let n=vJ(e,t.tabId),r=CJ(e,t.tabId),i=r.tabs.indexOf(t.tabId),a=RJ(e,[r.id]);if(r.host===`float`){let i=bJ(e,r.id);return{state:BJ(kJ(OJ({...e,floats:jJ(e.floats,i)},{[r.id]:null}),{[t.tabId]:null}),r.id),inverse:[{type:`insertPane`,pane:r,tabs:[n],attach:{mode:`float`,index:i}},a]}}let o=r.activeTabId===t.tabId?MJ(r.tabs,i):r.activeTabId;return{state:kJ(OJ(e,{[r.id]:NJ(r,jJ(r.tabs,i),o)}),{[t.tabId]:null}),inverse:[{type:`insertTab`,paneId:r.id,tab:n,index:i},a]}}function YJ(e,t){if(HJ(e,t.pane.id),t.pane.tabs.length!==t.tabs.length)throw Error(`layout: insertPane tab records do not match the pane`);if(t.pane.host===`dock`&&t.tabs.length>0)throw Error(`layout: insertPane returns a docked pane empty`);let n={};for(let r of t.tabs)UJ(e,r.id),n[r.id]=r;let r=t.tabs[0],i=r===void 0?[{type:`merge`,paneId:t.pane.id}]:[{type:`closeTab`,tabId:r.id},RJ(e,[])],a=t.attach;switch(a.mode){case`child`:{let r=_J(e,a.parentId),o=AJ(r.children,a.index,t.pane.id);if(a.sizes.length!==o.length)throw Error(`layout: insertPane sizes do not match the split`);return i.push({type:`resize`,splitId:r.id,sizes:r.sizes}),{state:OJ(kJ(e,n),{[t.pane.id]:t.pane,[r.id]:{...r,children:o,sizes:a.sizes}}),inverse:i}}case`wrap`:if(!a.split.children.includes(t.pane.id))throw Error(`layout: insertPane wrap split does not list the pane`);return{state:OJ(kJ(PJ(e,a.targetId,a.split.id),n),{[t.pane.id]:t.pane,[a.split.id]:a.split}),inverse:i};case`float`:{if(t.pane.host!==`float`)throw Error(`layout: float attachment requires a floating pane`);let r=AJ(e.floats,a.index,t.pane.id);return{state:OJ(kJ({...e,floats:r},n),{[t.pane.id]:t.pane}),inverse:i}}default:return mJ(a,`layout: insertPane attachment`)}}function XJ(e,t){let n=CJ(e,t.tabId);if(n.host!==`dock`)throw Error(`layout: moveTab source must be docked; use unfloat`);let r=gJ(e,t.toPaneId);if(r.host!==`dock`)throw Error(`layout: moveTab target must be docked`);if(r.id===n.id)throw Error(`layout: moveTab across one pane; use reorderTab`);let i=n.tabs.indexOf(t.tabId),a=RJ(e,[n.id,r.id]),o=n.activeTabId===t.tabId?MJ(n.tabs,i):n.activeTabId;return{state:{...OJ(e,{[n.id]:NJ(n,jJ(n.tabs,i),o),[r.id]:NJ(r,AJ(r.tabs,t.index,t.tabId),t.tabId)}),activePaneId:r.id},inverse:[{type:`moveTab`,tabId:t.tabId,toPaneId:n.id,index:i},a]}}function ZJ(e,t){let n=CJ(e,t.tabId),r=n.tabs.indexOf(t.tabId),i=AJ(jJ(n.tabs,r),t.index,t.tabId);return{state:OJ(e,{[n.id]:{...n,tabs:i}}),inverse:[{type:`reorderTab`,tabId:t.tabId,index:r}]}}function QJ(e,t){let n=CJ(e,t.tabId),r=RJ(e,[n.id]),i=OJ(e,{[n.id]:{...n,activeTabId:t.tabId}}),a=n.host===`float`?zJ(i.floats,n.id):i.floats;return{state:{...i,activePaneId:n.id,floats:a},inverse:[r]}}function $J(e,t){let n=gJ(e,t.paneId),r=RJ(e,[]),i=n.host===`float`?zJ(e.floats,n.id):e.floats;return{state:{...e,activePaneId:n.id,floats:i},inverse:[r]}}function eY(e,t){let n=_J(e,t.splitId);if(t.sizes.length!==n.children.length)throw Error(`layout: resize sizes do not match the split`);if(t.sizes.some(e=>!(e>0)))throw Error(`layout: resize sizes must all be above zero`);return{state:OJ(e,{[n.id]:{...n,sizes:TJ(t.sizes)}}),inverse:[{type:`resize`,splitId:n.id,sizes:n.sizes}]}}function tY(e,t){vJ(e,t.tabId);let n=CJ(e,t.tabId);if(n.host!==`dock`)throw Error(`layout: float requires a docked tab`);HJ(e,t.newPaneId);let r=n.tabs.indexOf(t.tabId),i=RJ(e,[n.id]),a=n.activeTabId===t.tabId?MJ(n.tabs,r):n.activeTabId,o=OJ(e,{[n.id]:NJ(n,jJ(n.tabs,r),a),[t.newPaneId]:{kind:`pane`,id:t.newPaneId,host:`float`,tabs:[t.tabId],activeTabId:t.tabId,rect:t.rect}});return{state:{...o,floats:[...o.floats,t.newPaneId],activePaneId:t.newPaneId},inverse:[{type:`unfloat`,paneId:t.newPaneId,toPaneId:n.id,index:r},i]}}function nY(e,t){let n=gJ(e,t.paneId),r=yJ(n),i=xJ(n),a=gJ(e,t.toPaneId);if(a.host!==`dock`)throw Error(`layout: unfloat target must be docked`);let o=RJ(e,[a.id]);return{state:{...OJ({...e,floats:jJ(e.floats,bJ(e,t.paneId))},{[t.paneId]:null,[a.id]:NJ(a,AJ(a.tabs,t.index,i),i)}),activePaneId:a.id},inverse:[{type:`float`,tabId:i,newPaneId:t.paneId,rect:r},o]}}function rY(e,t,n){let r=OJ(e,{[t.id]:{...t,rect:n}});return{...r,activePaneId:t.id,floats:zJ(r.floats,t.id)}}function iY(e,t){let n=gJ(e,t.paneId),r=yJ(n);return{state:rY(e,n,{...r,x:t.x,y:t.y}),inverse:[{type:`moveFloat`,paneId:t.paneId,x:r.x,y:r.y},RJ(e,[])]}}function aY(e,t){let n=gJ(e,t.paneId),r=yJ(n);if(!(t.rect.width>0)||!(t.rect.height>0))throw Error(`layout: float size must be above zero`);return{state:rY(e,n,t.rect),inverse:[{type:`resizeFloat`,paneId:t.paneId,rect:r},RJ(e,[])]}}function oY(e,t){let n=RJ(e,DJ(t.paneActiveTabs));for(let n of t.floats)if(gJ(e,n).host!==`float`)throw Error(`layout: restoreFocus lists docked pane ${n} as floating`);let r=e;for(let[e,n]of EJ(t.paneActiveTabs)){let t=gJ(r,e);r=OJ(r,{[e]:{...t,activeTabId:n}})}return gJ(r,t.activePaneId),{state:{...r,activePaneId:t.activePaneId,floats:t.floats},inverse:[n]}}function sY(e,t){switch(t.type){case`split`:return WJ(e,t);case`merge`:return GJ(e,t);case`openTab`:return KJ(e,t);case`insertTab`:return qJ(e,t);case`closeTab`:return JJ(e,t);case`insertPane`:return YJ(e,t);case`moveTab`:return XJ(e,t);case`reorderTab`:return ZJ(e,t);case`focusTab`:return QJ(e,t);case`focusPane`:return $J(e,t);case`resize`:return eY(e,t);case`float`:return tY(e,t);case`unfloat`:return nY(e,t);case`moveFloat`:return iY(e,t);case`resizeFloat`:return aY(e,t);case`setExpanded`:return{state:{...e,expanded:t.expanded},inverse:[{type:`setExpanded`,expanded:e.expanded}]};case`setMode`:return{state:{...e,mode:t.mode},inverse:[{type:`setMode`,mode:e.mode}]};case`restoreFocus`:return oY(e,t);default:return mJ(t,`layout: operation`)}}function cY(e,t){return t.reduce((e,t)=>sY(e,t).state,e)}var lY={entries:[],cursor:0},uY=new Set([`focusTab`,`focusPane`,`restoreFocus`]);function dY(e){return uY.has(e.type)}function fY(e,t){let n=e.entries[t];return n!==void 0&&n.ops.every(dY)}function pY(e){return e.cursor>0}function mY(e){return e.cursor<e.entries.length}function hY(e){return e.entries.flatMap(e=>e.ops)}function gY(e,t,n){if(n.length===0)return{history:e,state:t};let r=t,i=[];for(let e of n){let t=sY(r,e);r=t.state,i.unshift(...t.inverse)}return{history:{entries:[...e.cursor===e.entries.length?e.entries:e.entries.slice(0,e.cursor),{ops:n,inverse:i}],cursor:e.cursor+1},state:r}}function _Y(e,t){if(!pY(e))return;let n=1;if(fY(e,e.cursor-1))for(;fY(e,e.cursor-1-n);)n+=1;let r=t;for(let t of e.entries.slice(e.cursor-n,e.cursor).reverse())for(let e of t.inverse)r=sY(r,e).state;return{history:{entries:e.entries,cursor:e.cursor-n},state:r}}function vY(e,t){if(!mY(e))return;let n=1;if(fY(e,e.cursor))for(;fY(e,e.cursor+n);)n+=1;let r=t;for(let t of e.entries.slice(e.cursor,e.cursor+n))for(let e of t.ops)r=sY(r,e).state;return{history:{entries:e.entries,cursor:e.cursor+n},state:r}}var yY=class{current;recorded=lY;constructor(e){this.current=e}get state(){return this.current}get history(){return this.recorded}get ops(){return hY(this.recorded)}get cursor(){return this.recorded.cursor}get canUndo(){return pY(this.recorded)}get canRedo(){return mY(this.recorded)}dispatch(e){return this.dispatchAll([e])}dispatchAll(e){let t=gY(this.recorded,this.current,e);return this.recorded=t.history,this.current=t.state,this.current}undo(){let e=_Y(this.recorded,this.current);return e!==void 0&&(this.recorded=e.history,this.current=e.state,!0)}redo(){let e=vY(this.recorded,this.current);return e!==void 0&&(this.recorded=e.history,this.current=e.state,!0)}},bY=.12,xY={width:380,height:300},SY={width:220,height:140},CY=.25;function wY(e){return wJ(e).length}function TY(e){return wY(e)<4}function EY(e,t,n=CY){let r=`left`,i=e;return 1-e<i&&(r=`right`,i=1-e),t<i&&(r=`top`,i=t),1-t<i&&(r=`bottom`,i=1-t),i<n?r:`center`}function DY(e){switch(e){case`center`:return;case`left`:return{axis:`row`,direction:`before`};case`right`:return{axis:`row`,direction:`after`};case`top`:return{axis:`column`,direction:`before`};case`bottom`:return{axis:`column`,direction:`after`};default:return mJ(e,`layout: dock zone`)}}function OY(e,t=bY){if(e.length===0)return[];let n=Math.min(t,1/e.length),r=e.map(e=>e>0?e:0),i=r.reduce((e,t)=>e+t,0),a=i>0?r.map(e=>e/i):r.map(()=>1/e.length),o=new Set;for(;;){let e=a.flatMap((e,t)=>!o.has(t)&&e<n?[t]:[]);if(e.length===0)return a;for(let t of e)o.add(t);let t=1-o.size*n,r=a.reduce((e,t,n)=>o.has(n)?e:e+t,0);a=a.map((e,i)=>o.has(i)?n:e/r*t)}}function kY(e,t,n){return t>=e.x&&t<=e.x+e.width&&n>=e.y&&n<=e.y+e.height}function AY(e,t,n,r=CY){return!(e.width>0)||!(e.height>0)?`center`:EY((t-e.x)/e.width,(n-e.y)/e.height,r)}function jY(e,t){let n=0;for(let r of e){if(t<r.x+r.width/2)break;n+=1}return n}var MY={divider:0,chip:100,body:48};function NY(e,t=MY){let{pane:n,strip:r}=e;if(!(n.width>0)||!(n.height>0)||!(r.width>0))return{row:!0,column:!0};let i=Math.max(0,n.width-r.width),a=Math.max(0,r.width-e.chipsWidth-e.fillWidth-(e.splitControlWidth??0)),o=(n.width-t.divider)/2-i,s=(n.height-t.divider)/2-i;return{row:o>=a+t.chip,column:s>=r.height+t.body}}function PY(e,t,n,r){return Math.abs(n-e)>=4||Math.abs(r-t)>=4}function FY(e,t,n){let r=e[t],i=e[t+1];if(r===void 0||i===void 0)return[...e];let a=[...e];return a[t]=r+n,a[t+1]=i-n,a}function IY(e,t,n){return{...e,x:e.x+t,y:e.y+n}}function LY(e,t,n,r){return{...e,width:Math.max(r.width,e.width+t),height:Math.max(r.height,e.height+n)}}function RY(e,t,n){return{x:Math.max(0,e-zY.x),y:Math.max(0,t-zY.y),...n}}var zY={x:60,y:14},BY=24,VY={x:160,y:120},HY=[];function UY(e,t,n,r){for(let i of gJ(e,t).tabs){let t=e.tabs[i];if(t?.contentId===n&&(r===void 0||t.kind===r))return i}}function WY(e,t,n){for(let r of[...wJ(e),...e.floats]){let i=UY(e,r,t,n);if(i!==void 0)return i}}function GY(e){let t=gJ(e,e.activePaneId);return t.host===`dock`?t.id:IJ(e)}function KY(e,t,n,r){return e.host===`float`?{type:`unfloat`,paneId:e.id,toPaneId:n,index:r}:{type:`moveTab`,tabId:t,toPaneId:n,index:r}}function qY(e,t){return e.expanded===t?HY:[{type:`setExpanded`,expanded:t}]}function JY(e,t){return e.mode===t?HY:[{type:`setMode`,mode:t}]}function YY(e,t,n,r){if(!TY(e))return HY;let i=n??GY(e);if(gJ(e,i).host!==`dock`)return HY;let a=t(`pane`),o=[{type:`split`,paneId:i,axis:`row`,direction:`after`,newPaneId:a,newSplitId:t(`split`)}],s=r?.(t(`tab`));return s!==void 0&&o.push({type:`openTab`,paneId:a,tab:s,index:0}),o}function XY(e,t,n,r){if(r===void 0)return HY;let i=gJ(e,n);return i.host===`dock`?[{type:`openTab`,paneId:n,tab:r(t(`tab`)),index:i.tabs.length}]:HY}function ZY(e,t,n){let r=n.revealIfOpened===!1?void 0:WY(e,n.contentId,n.kind);if(r!==void 0)return{ops:[{type:`focusTab`,tabId:r}],tabId:r};let i=n.paneId??GY(e),a={id:t(`tab`),kind:n.kind,contentId:n.contentId,title:n.title};return{ops:[{type:`openTab`,paneId:i,tab:a,index:n.index??gJ(e,i).tabs.length}],tabId:a.id}}function QY(e,t,n){let r=vJ(e,n),i=CJ(e,n),a=i.host===`dock`?i.id:GY(e),o=i.host===`dock`?i.tabs.indexOf(n)+1:gJ(e,a).tabs.length,s={...r,id:t(`tab`)};return{ops:[{type:`openTab`,paneId:a,tab:s,index:o}],tabId:s.id}}function $Y(e,t,n,r){let i=CJ(e,t);if(gJ(e,n).host!==`dock`)return HY;if(i.id===n){let e=i.tabs.indexOf(t),n=r>e?r-1:r;return n===e?HY:[{type:`reorderTab`,tabId:t,index:n}]}return[KY(i,t,n,r)]}function eX(e,t,n,r,i,a){let o=CJ(e,n),s=gJ(e,r);if(s.host!==`dock`)return HY;let c=DY(i);if(c===void 0)return o.id===r?HY:[KY(o,n,r,s.tabs.length)];let l=o.id===r&&o.tabs.length===1;if(l&&a===void 0||!TY(e))return HY;let u=t(`pane`),d=[{type:`split`,paneId:r,axis:c.axis,direction:c.direction,newPaneId:u,newSplitId:t(`split`)}];return l&&a!==void 0&&d.push({type:`openTab`,paneId:r,tab:a(t(`tab`)),index:o.tabs.length}),d.push(KY(o,n,u,0)),d}function tX(e,t,n,r){let i=e.floats.length*BY,a=t(`float`);return{ops:[{type:`float`,tabId:n,newPaneId:a,rect:r??{x:VY.x+i,y:VY.y+i,width:xY.width,height:xY.height}}],paneId:a}}function nX(e,t,n){let r=n??GY(e);return[{type:`unfloat`,paneId:t,toPaneId:r,index:gJ(e,r).tabs.length}]}function rX(e,t,n){return[{type:`resize`,splitId:e,sizes:OY(t,n)}]}function iX(e,t,n){let r=[],i=e;for(;;){let e=wJ(i).find(e=>e!==i.rootId&&gJ(i,e).tabs.length===0);if(e===void 0)break;let t={type:`merge`,paneId:e};r.push(t),i=sY(i,t).state}let a=hJ(i,i.rootId);return a.kind===`pane`&&a.tabs.length===0&&n!==void 0&&r.push({type:`openTab`,paneId:a.id,tab:n(t(`tab`)),index:0}),r}function aX(e=0){let t=e;return{next:(e=>(t+=1,`${e}${t}`))}}function oX(e,t,n=`push`){let r=e.next(`pane`),i=t?.(e.next(`tab`));return{nodes:{[r]:{kind:`pane`,id:r,host:`dock`,tabs:i===void 0?[]:[i.id],activeTabId:i?.id,rect:void 0}},tabs:i===void 0?{}:{[i.id]:i},rootId:r,floats:[],activePaneId:r,expanded:!1,mode:n}}var sX=class{minter;sequencer;listeners=new Set;makePaneTab;snapshot;constructor(e={}){this.minter=aX(),this.makePaneTab=e.makePaneTab,this.sequencer=new yY(oX(this.minter,e.makeInitialTab,e.mode)),this.snapshot=this.buildSnapshot()}subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});getSnapshot=()=>this.snapshot;get ops(){return this.sequencer.ops}buildSnapshot(){let e=this.sequencer.state;return{state:e,canUndo:this.sequencer.canUndo,canRedo:this.sequencer.canRedo,canSplit:TY(e),opCount:this.sequencer.ops.length,cursor:this.sequencer.cursor}}commit(){this.snapshot=this.buildSnapshot();for(let e of[...this.listeners])e()}get state(){return this.sequencer.state}get mint(){return this.minter.next}run(e,t=!1){if(e.length===0)return!1;if(t){let t=cY(this.state,e);e=[...e,...iX(t,this.mint,t.floats.length>0?this.makePaneTab:void 0)]}return this.sequencer.dispatchAll(e),this.commit(),!0}setExpanded(e){this.run(qY(this.state,e))}toggleExpanded(){this.setExpanded(!this.state.expanded)}setMode(e){this.run(JY(this.state,e))}splitPane(e){return this.run(YY(this.state,this.mint,e,this.makePaneTab))}addTab(e){return this.run(XY(this.state,this.mint,e,this.makePaneTab))}openContent(e){let t=ZY(this.state,this.mint,e);return this.run(t.ops),t.tabId}duplicateTab(e){let t=QY(this.state,this.mint,e);return this.run(t.ops),t.tabId}closeTab(e){this.run([{type:`closeTab`,tabId:e}],!0)}focusTab(e){this.run([{type:`focusTab`,tabId:e}])}focusPane(e){this.run([{type:`focusPane`,paneId:e}])}reorderTab(e,t){this.run([{type:`reorderTab`,tabId:e,index:t}])}placeTab(e,t,n){return this.run($Y(this.state,e,t,n),!0)}dropTab(e,t,n){return this.run(eX(this.state,this.mint,e,t,n),!0)}floatTab(e,t){let n=tX(this.state,this.mint,e,t);return this.run(n.ops,!0),n.paneId}unfloatPane(e,t){this.run(nX(this.state,e,t))}moveFloat(e,t,n){this.run([{type:`moveFloat`,paneId:e,x:t,y:n}])}resizeFloat(e,t){this.run([{type:`resizeFloat`,paneId:e,rect:t}])}resizeSplit(e,t){this.run(rX(e,t))}undo(){return this.sequencer.undo()?(this.commit(),!0):!1}redo(){return this.sequencer.redo()?(this.commit(),!0):!1}activeDockPaneId(){return GY(this.state)}},cX={x:0,y:0,width:0,height:0},lX={row:!0,column:!0};function uX(e){return e===null?cX:e.getBoundingClientRect()}function dX(e){let t=Number.parseFloat(e);return Number.isFinite(t)?t:0}function fX(e){let t=[];for(let n of e.querySelectorAll(`[data-dockkit-pane]`)){let e=n.dataset.dockkitPane;e!==void 0&&t.push([e,n])}return t}function pX(e){let t=e.querySelector(`[data-dockkit-tab]`);if(t===null)return MY.chip;let n=getComputedStyle(t),r=dX(n.minWidth);return r<=0?MY.chip:n.boxSizing===`border-box`?r:r+dX(n.paddingLeft)+dX(n.paddingRight)+dX(n.borderLeftWidth)+dX(n.borderRightWidth)}function mX(e){let t=e.querySelector(`[data-dockkit-divider]`);if(t===null)return MY.divider;let{width:n,height:r}=t.getBoundingClientRect(),i=Math.min(n,r);return i>0?i:MY.divider}function hX(e){let t=e.querySelector(`[data-dockkit-split-button]`);if(t===null)return 0;let n=t.getBoundingClientRect().width;if(!(n>0))return 0;let r=e.querySelector(`[data-dockkit-strip]`);return n+(r===null?0:dX(getComputedStyle(r).columnGap))}function gX(e,t=!1){let n={divider:mX(e),chip:pX(e),body:MY.body},r=new Map;for(let[i,a]of fX(e))r.set(i,NY({pane:uX(a),strip:uX(a.querySelector(`[data-dockkit-strip]`)),chipsWidth:uX(a.querySelector(`[data-dockkit-strip-tabs]`)).width,fillWidth:uX(a.querySelector(`[data-dockkit-strip-fill]`)).width,splitControlWidth:t?hX(a):0},n));return r}function _X(e,t){return e.get(t)??lX}function vX(e,t){if(e.size!==t.size)return!1;for(let[n,r]of e){let e=t.get(n);if(e===void 0||e.row!==r.row||e.column!==r.column)return!1}return!0}function yX(e,t){typeof e.setPointerCapture==`function`&&e.setPointerCapture(t)}function bX(e,t,n){yX(e,t);let r=new AbortController,{signal:i}=r;e.dataset.dockkitPointer=String(t),i.addEventListener(`abort`,()=>{e.dataset.dockkitPointer===String(t)&&delete e.dataset.dockkitPointer},{once:!0});let a=e=>e.pointerId===t;return window.addEventListener(`pointermove`,e=>{a(e)&&n.move(e)},{signal:i}),window.addEventListener(`pointerup`,e=>{a(e)&&(r.abort(),n.up(e))},{signal:i}),window.addEventListener(`pointercancel`,e=>{a(e)&&(r.abort(),n.cancel())},{signal:i}),()=>{r.abort()}}function xX(e){let t=(0,P.useRef)(void 0);return(0,P.useEffect)(()=>()=>{t.current?.stop()},[]),(n,r,i)=>{t.current?.end();let a=()=>{t.current=void 0,e()},o=bX(n,r,{move:i.move,up:e=>{a(),i.up(e)},cancel:a});t.current={stop:o,end:()=>{o(),a()}}}}var SX=new WeakMap,CX=new Set([`Tab`,`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`,`Home`,`End`]);function wX(e,t){SX.get(e)?.();let n=()=>{e.removeAttribute(`data-dsh-automatic-focus`),e.removeEventListener(`blur`,n),e.removeEventListener(`keydown`,r,!0),SX.delete(e)},r=e=>{e.isComposing||e.ctrlKey||e.altKey||e.metaKey||!CX.has(e.key)||n()};SX.set(e,n),e.setAttribute(`data-dsh-automatic-focus`,``),e.addEventListener(`blur`,n),e.addEventListener(`keydown`,r,!0),e.focus(t),e.matches(`:focus`)||n()}function TX(e){let t=!1,n=!1,r=()=>{t=!0},i=()=>{t=!1,n=!0},a=()=>{n=!1},o=()=>{t=!1,n=!1};return e.addEventListener(`compositionstart`,r,!0),e.addEventListener(`compositionend`,i,!0),e.addEventListener(`keyup`,a,!0),e.defaultView?.addEventListener(`blur`,o),{guards:e=>{let r=t||n||e.isComposing||e.keyCode===229;return n=!1,r},dispose:()=>{e.removeEventListener(`compositionstart`,r,!0),e.removeEventListener(`compositionend`,i,!0),e.removeEventListener(`keyup`,a,!0),e.defaultView?.removeEventListener(`blur`,o)}}}var EX=new WeakMap,DX=`button:not(:disabled), input:not(:disabled), textarea:not(:disabled), select:not(:disabled), a[href], [tabindex="0"]`;function OX(e,t,n){let r=(0,P.useRef)(n);r.current=n,(0,P.useLayoutEffect)(()=>{let n=e.current;if(!t||n===null)return;let i=n.ownerDocument,a=TX(i),o=i.activeElement,s=EX.get(i)??[];EX.set(i,s);let c={element:n,close:()=>{r.current()}};s.push(c);let l=n.querySelector(`[data-modal-autofocus]`)??n.querySelector(DX)??n;n.contains(i.activeElement)||wX(l);let u=e=>{let t=a.guards(e);if(s.at(-1)!==c||e.defaultPrevented||t||e.ctrlKey||e.altKey||e.metaKey||(e.key===`Escape`&&!e.shiftKey&&(e.preventDefault(),e.repeat||r.current()),e.key!==`Tab`)||i.activeElement?.closest(`[role="menu"]`))return;let o=[...n.querySelectorAll(DX)].filter(e=>!e.closest(`[inert], [hidden]`)),l=o[0]??n,u=o.at(-1)??n,d=e.shiftKey?i.activeElement===l:i.activeElement===u;(i.activeElement===n||!n.contains(i.activeElement)||d)&&(e.preventDefault(),(e.shiftKey?u:l).focus())};return i.addEventListener(`keydown`,u),()=>{a.dispose();let e=s.at(-1)===c;if(s.splice(s.indexOf(c),1),i.removeEventListener(`keydown`,u),s.length===0&&EX.delete(i),e){let e=o instanceof HTMLElement&&o.isConnected?o:s.at(-1)?.element;e!==void 0&&wX(e)}}},[e,t])}var kX={split:`_split_1s7ij_17`,splitRow:`_splitRow_1s7ij_24`,splitColumn:`_splitColumn_1s7ij_28`,splitCell:`_splitCell_1s7ij_32`,divider:`_divider_1s7ij_39`,surface:`_surface_1s7ij_125`,tabLayout:`_tabLayout_1s7ij_134`,tabCell:`_tabCell_1s7ij_142`,emptyTabHost:`_emptyTabHost_1s7ij_143`,floatingCell:`_floatingCell_1s7ij_156`,tabHost:`_tabHost_1s7ij_162`,float:`_float_1s7ij_156`,tabHostHeader:`_tabHostHeader_1s7ij_177`,tabHostBody:`_tabHostBody_1s7ij_181`,tabLayoutDivider:`_tabLayoutDivider_1s7ij_186`,pane:`_pane_1s7ij_209`,tabStrip:`_tabStrip_1s7ij_237`,stripTabs:`_stripTabs_1s7ij_257`,stripFill:`_stripFill_1s7ij_288`,stripChrome:`_stripChrome_1s7ij_296`,paneBody:`_paneBody_1s7ij_318`,slot:`_slot_1s7ij_327`,tabActive:`_tabActive_1s7ij_346`,slotCaret:`_slotCaret_1s7ij_346`,tab:`_tab_1s7ij_134`,tabTitle:`_tabTitle_1s7ij_389`,floatTitle:`_floatTitle_1s7ij_409`,tabClose:`_tabClose_1s7ij_417`,addTab:`_addTab_1s7ij_449`,tabQuiet:`_tabQuiet_1s7ij_488`,tabDragging:`_tabDragging_1s7ij_505`,iconButton:`_iconButton_1s7ij_511`,menu:`_menu_1s7ij_547`,menuItem:`_menuItem_1s7ij_561`,empty:`_empty_1s7ij_143`,dockScrim:`_dockScrim_1s7ij_599`,dockScrimIn:`_dockScrimIn_1s7ij_1`,dockHint:`_dockHint_1s7ij_601`,dockHintCard:`_dockHintCard_1s7ij_606`,dockHintIn:`_dockHintIn_1s7ij_1`,dockHintLabel:`_dockHintLabel_1s7ij_694`,floatHeader:`_floatHeader_1s7ij_765`,dockGlyph:`_dockGlyph_1s7ij_782`,floatBody:`_floatBody_1s7ij_787`,floatResize:`_floatResize_1s7ij_797`},AX=4;function jX(e,t){let n=e.getBoundingClientRect(),r=t.offsetWidth,i=n.left+r+AX>window.innerWidth?Math.max(AX,n.right-r):n.left;return{top:n.bottom+AX,left:i}}function MX({labels:e,anchor:t,onClose:n,onDismiss:r,extras:i}){let a=(0,P.useRef)(null),[o,s]=(0,P.useState)(void 0),c=n!==void 0||P.Children.toArray(i).some(e=>e!==``);return(0,P.useLayoutEffect)(()=>{a.current!==null&&s(jX(t,a.current))},[t,c]),(0,P.useEffect)(()=>{let e=a.current;if(e===null)return;let n=e.ownerDocument,i=TX(n),o=a=>{if(i.guards(a)||a.defaultPrevented||a.key!==`Escape`||a.ctrlKey||a.altKey||a.metaKey||a.shiftKey||[...n.querySelectorAll(`[role="dialog"][aria-modal="true"], [role="menu"]`)].at(-1)!==e||(a.preventDefault(),a.repeat))return;let o=e.contains(n.activeElement);r(),o&&wX(t)};n.addEventListener(`keydown`,o,!0);let s=t=>{t.target instanceof Node&&e.contains(t.target)||r()};return window.addEventListener(`pointerdown`,s,!0),()=>{i.dispose(),n.removeEventListener(`keydown`,o,!0),window.removeEventListener(`pointerdown`,s,!0)}},[t,r,c]),c?(0,jt.createPortal)((0,F.jsxs)(kp,{className:kX.menu,ref:a,role:`menu`,"data-dockkit-tab-menu":!0,style:o??{visibility:`hidden`,top:0,left:0},onPointerDown:e=>{e.stopPropagation()},onClick:e=>{e.stopPropagation()},children:[n!==void 0&&(0,F.jsx)(`button`,{type:`button`,role:`menuitem`,className:kX.menuItem,"data-dockkit-menu-close":!0,onClick:n,children:e.closeTab}),i]}),document.body):null}function NX(e){e.scrollWidth>e.clientWidth+1?e.dataset.dockkitTabClipped=``:delete e.dataset.dockkitTabClipped}function PX({children:e}){let t=(0,P.useRef)(null);return(0,P.useLayoutEffect)(()=>{t.current!==null&&NX(t.current)}),(0,P.useLayoutEffect)(()=>{let e=t.current;if(e===null||typeof ResizeObserver>`u`)return;let n=new ResizeObserver(()=>{NX(e)});return n.observe(e),()=>{n.disconnect()}},[]),(0,F.jsx)(`span`,{ref:t,className:kX.tabTitle,"data-dockkit-tab-title":!0,children:e})}var FX=`M9.67272 0.522841C10.8339 0.522841 11.76 0.522714 12.4963 0.602493C13.2453 0.683657 13.8789 0.854248 14.4264 1.25197C14.7504 1.48739 15.0355 1.77247 15.2709 2.0965C15.6686 2.64394 15.8392 3.27758 15.9204 4.02655C16.0002 4.7629 16 5.68895 16 6.85014V9.14986C16 10.3111 16.0002 11.2371 15.9204 11.9735C15.8392 12.7224 15.6686 13.3561 15.2709 13.9035C15.0355 14.2275 14.7504 14.5126 14.4264 14.748C13.8789 15.1458 13.2453 15.3163 12.4963 15.3975C11.76 15.4773 10.8339 15.4772 9.67272 15.4772H6.3273C5.16611 15.4772 4.24006 15.4773 3.50371 15.3975C2.75474 15.3163 2.1211 15.1458 1.57366 14.748C1.24963 14.5126 0.964549 14.2275 0.729131 13.9035C0.331407 13.3561 0.160817 12.7224 0.0796529 11.9735C-0.000126137 11.2371 1.25338e-09 10.3111 1.25338e-09 9.14986V6.85014C1.25329e-09 5.68895 -0.000126137 4.7629 0.0796529 4.02655C0.160817 3.27758 0.331407 2.64394 0.729131 2.0965C0.964549 1.77247 1.24963 1.48739 1.57366 1.25197C2.1211 0.854248 2.75474 0.683657 3.50371 0.602493C4.24006 0.522714 5.16611 0.522841 6.3273 0.522841H9.67272ZM4.1828 14.0873L5.54303 14.1118C5.78636 14.1128 6.04709 14.1169 6.3273 14.1169H9.67272C10.8639 14.1169 11.7032 14.1164 12.3493 14.0465C12.9824 13.9779 13.3497 13.8494 13.6268 13.6482C13.8354 13.4966 14.0195 13.3125 14.1711 13.1039C14.3723 12.8268 14.5007 12.4595 14.5693 11.8264C14.6393 11.1803 14.6398 10.341 14.6398 9.14986V6.85014C14.6398 5.65896 14.6393 4.81967 14.5693 4.1736C14.5007 3.54048 14.3723 3.17318 14.1711 2.89609C14.0195 2.68747 13.8354 2.50337 13.6268 2.35179C13.3497 2.1506 12.9824 2.02212 12.3493 1.95353C11.7032 1.88358 10.8639 1.88307 9.67272 1.88307H6.3273C6.04709 1.88307 5.78636 1.8862 5.54303 1.88715L4.1828 1.91166C3.99125 1.9216 3.8148 1.93577 3.65076 1.95353C3.01764 2.02212 2.65034 2.1506 2.37325 2.35179C2.16463 2.50337 1.98052 2.68747 1.82895 2.89609C1.62776 3.17318 1.49928 3.54048 1.43069 4.1736C1.36074 4.81967 1.36023 5.65896 1.36023 6.85014V9.14986C1.36023 10.341 1.36074 11.1803 1.43069 11.8264C1.49928 12.4595 1.62776 12.8268 1.82895 13.1039C1.98052 13.3125 2.16463 13.4966 2.37325 13.6482C2.65034 13.8494 3.01764 13.9779 3.65076 14.0465C3.81478 14.0642 3.99127 14.0774 4.1828 14.0873Z`;function IX(){return(0,F.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,children:[(0,F.jsx)(`path`,{d:`M13.5 1.5H2.5C1.94772 1.5 1.5 1.94772 1.5 2.5V13.5C1.5 14.0523 1.94772 14.5 2.5 14.5H13.5C14.0523 14.5 14.5 14.0523 14.5 13.5V2.5C14.5 1.94772 14.0523 1.5 13.5 1.5Z`,stroke:`currentColor`}),(0,F.jsx)(`path`,{d:`M8 1.5V14.5`,stroke:`currentColor`})]})}var LX={center:`M4.56 3.48H11.44A1.6 1.6 0 0 1 13.04 5.08V10.92A1.6 1.6 0 0 1 11.44 12.52H4.56A1.6 1.6 0 0 1 2.96 10.92V5.08A1.6 1.6 0 0 1 4.56 3.48Z`,left:`M4 0.523H8V15.477H4A4 4 0 0 1 0 11.477V4.523A4 4 0 0 1 4 0.523Z`,right:`M8 0.523H12A4 4 0 0 1 16 4.523V11.477A4 4 0 0 1 12 15.477H8Z`,top:`M0 8V4.523A4 4 0 0 1 4 0.523H12A4 4 0 0 1 16 4.523V8Z`,bottom:`M0 8H16V11.477A4 4 0 0 1 12 15.477H4A4 4 0 0 1 0 11.477Z`};function RX({zone:e}){return(0,F.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,children:[(0,F.jsx)(`path`,{fillRule:`evenodd`,clipRule:`evenodd`,d:FX,fill:`currentColor`}),(0,F.jsx)(`path`,{d:LX[e],fill:`currentColor`})]})}function zX({zone:e,active:t,labels:n}){return(0,F.jsx)(`div`,{className:kX.dockHint,"data-dockkit-dock-zone":e,"data-dockkit-drop-active":t||void 0,children:(0,F.jsxs)(`div`,{className:kX.dockHintCard,children:[(0,F.jsx)(RX,{zone:e}),(0,F.jsx)(`span`,{className:kX.dockHintLabel,children:n.dropZone[e]})]})})}function BX(e,t,n){let r=t.length,i=t.indexOf(n);switch(e){case`ArrowLeft`:return t[(i-1+r)%r];case`ArrowRight`:return t[(i+1)%r];case`Home`:return t[0];case`End`:return t.at(-1);default:return}}function VX(e){return e===`Enter`||e===` `}function HX(e){let t=e.scrollLeft>1,n=e.scrollLeft+e.clientWidth<e.scrollWidth-1;if(t&&n)return`start end`;if(t)return`start`;if(n)return`end`}function UX(e,t){(0,P.useLayoutEffect)(()=>{let t=e.current;if(t===null)return;let n=()=>{let e=HX(t);e===void 0?delete t.dataset.dockkitStripScroll:t.dataset.dockkitStripScroll=e};n(),t.addEventListener(`scroll`,n,{passive:!0});let r=typeof ResizeObserver>`u`?void 0:new ResizeObserver(n);return r?.observe(t),()=>{t.removeEventListener(`scroll`,n),r?.disconnect()}},[e,t])}function WX(e,t,n,r){(0,P.useLayoutEffect)(()=>{let n=e.current,i=r===void 0?void 0:t.get(r);if(n===null||i===void 0)return;let a=n.getBoundingClientRect(),o=i.getBoundingClientRect();o.left<a.left?n.scrollLeft+=o.left-a.left-GX:o.right>a.right&&(n.scrollLeft+=o.right-a.right+GX)},[e,t,n,r])}var GX=24;function KX(e,t){switch(t){case`budget`:return e.splitPaneDisabled;case`width`:return e.splitPaneNarrow}}function qX({state:e,pane:t,callbacks:r}){let[i,a]=(0,P.useState)(void 0),[o]=(0,P.useState)(()=>new Map),s=(0,P.useRef)(null);UX(s,t.tabs),WX(s,o,t.tabs,t.activeTabId);let c=r.splitBlock(t.id),l=r.dropTarget,u=l!==void 0&&l.kind===`strip`&&l.paneId===t.id?l.index:void 0,d=n=>{(e.activePaneId!==t.id||t.activeTabId!==n)&&r.onFocusTab(n)},f=e=>{let t=o.get(e);t!==void 0&&t.focus()};return(0,F.jsxs)(`div`,{className:kX.tabStrip,role:`tablist`,"data-dockkit-strip":t.id,"data-window-drag":e.floats.length===0||void 0,children:[(0,F.jsxs)(`div`,{ref:s,className:kX.stripTabs,role:`presentation`,"data-dockkit-strip-tabs":t.id,children:[t.tabs.map((s,c)=>{let l=vJ(e,s),p=s===t.activeTabId,m=r.canCloseTab(s),h=!m&&t.tabs.length===1;return(0,F.jsxs)(P.Fragment,{children:[(c>0||u===c)&&(0,F.jsx)(`div`,{className:n(kX.slot,u===c&&kX.slotCaret),"data-dockkit-caret":u===c?c:void 0}),(0,F.jsxs)(`div`,{role:`tab`,"aria-selected":p,tabIndex:p?0:-1,className:n(kX.tab,p&&kX.tabActive,h&&kX.tabQuiet,r.draggingTabId===s&&kX.tabDragging),"data-dockkit-tab":s,"data-dockkit-tab-quiet":h||void 0,ref:e=>{e===null?o.delete(s):o.set(s,e)},onPointerDown:e=>{e.button!==2&&r.onTabPressed(s,e)},onClick:e=>{e.stopPropagation(),d(s)},onKeyDown:e=>{if(e.target!==e.currentTarget||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey||e.nativeEvent.isComposing)return;let n=BX(e.key,t.tabs,s);n===void 0?VX(e.key)&&(e.preventDefault(),d(s)):(e.preventDefault(),f(n))},onContextMenu:e=>{e.preventDefault();let t=e.currentTarget;a(e=>e?.tabId===s?void 0:{tabId:s,anchor:t})},children:[(0,F.jsx)(PX,{children:r.renderTabTitle?.(l)??l.title}),m&&(0,F.jsx)(hO,{disabled:i!==void 0,label:r.labels.closeTab,shortcutKeys:r.labels.closeTabKeys,side:`bottom`,delayMs:500,children:(0,F.jsx)(`button`,{type:`button`,className:kX.tabClose,"aria-label":r.labels.closeTab,"aria-keyshortcuts":r.labels.closeTabShortcut,"data-dockkit-tab-close":s,onPointerDown:e=>{e.stopPropagation()},onClick:e=>{e.stopPropagation(),r.onCloseTab(s)},children:(0,F.jsx)(le,{size:14})})}),i?.tabId===s&&(0,F.jsx)(MX,{labels:r.labels,anchor:i.anchor,onClose:m?()=>{a(void 0),r.onCloseTab(s)}:void 0,onDismiss:()=>{a(void 0)},extras:r.renderTabMenuItems?.(l,()=>{a(void 0)})})]})]},s)}),u===t.tabs.length&&(0,F.jsx)(`div`,{className:n(kX.slot,kX.slotCaret),"data-dockkit-caret":u})]}),r.canAddTab(t.id)&&(0,F.jsx)(hO,{label:r.labels.addTab,side:`bottom`,delayMs:500,children:(0,F.jsx)(`button`,{type:`button`,className:kX.addTab,"aria-label":r.labels.addTab,"data-dockkit-add-tab":t.id,onClick:e=>{e.stopPropagation(),r.onAddTab(t.id)},children:(0,F.jsx)(me,{size:14})})}),(0,F.jsx)(`div`,{className:kX.stripFill,"data-dockkit-strip-fill":!0}),!(r.hideSplitWhenBlocked&&c!==void 0)&&(0,F.jsx)(hO,{label:c===void 0?r.labels.splitPane:KX(r.labels,c),shortcutKeys:r.labels.splitPaneKeys,side:`bottom`,delayMs:500,children:(0,F.jsx)(`span`,{tabIndex:c===void 0?void 0:0,"aria-label":c===void 0?void 0:KX(r.labels,c),children:(0,F.jsx)(`button`,{type:`button`,className:kX.iconButton,"aria-label":r.labels.splitPane,"aria-keyshortcuts":r.labels.splitPaneShortcut,disabled:c!==void 0,"data-dockkit-split-button":t.id,"data-dockkit-split-blocked":c,onClick:e=>{e.stopPropagation(),r.onSplitPane(t.id)},children:(0,F.jsx)(IX,{})})})}),t.id===r.chromePaneId&&r.chrome!==void 0&&(0,F.jsx)(`div`,{className:kX.stripChrome,"data-dockkit-strip-chrome":!0,onClick:e=>{e.stopPropagation()},children:r.chrome})]})}function JX({pane:e,callbacks:t}){let n=t.dropTarget,r=n?.kind===`zone`&&n.paneId===e.id?n.zone:void 0;return r===void 0?null:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`div`,{className:kX.dockScrim,"data-dockkit-dock-scrim":!0}),t.horizontalDrops&&r!==`center`?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(zX,{zone:`left`,active:r===`left`,labels:t.labels}),(0,F.jsx)(zX,{zone:`right`,active:r===`right`,labels:t.labels})]}):(0,F.jsx)(zX,{zone:r,active:!0,labels:t.labels})]})}function YX({state:e,pane:t,callbacks:n}){let r=t.activeTabId===void 0?void 0:vJ(e,t.activeTabId);return(0,F.jsxs)(`section`,{className:kX.pane,"data-dockkit-pane":t.id,tabIndex:-1,"data-dockkit-pane-active":e.activePaneId===t.id||void 0,onClick:()=>{e.activePaneId!==t.id&&n.onFocusPane(t.id)},children:[(0,F.jsx)(qX,{state:e,pane:t,callbacks:n}),(0,F.jsxs)(`div`,{className:kX.paneBody,children:[r===void 0?(0,F.jsx)(`p`,{className:kX.empty,children:n.labels.emptyPane}):n.renderTab(r),(0,F.jsx)(JX,{pane:t,callbacks:n})]})]})}function XX(e,t,n){let r=t-e.originX,i=n-e.originY;return e.mode===`move`?IY(e.rect,r,i):LY(e.rect,r,i,SY)}function ZX(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function QX(e,t){return e.activePaneId===t&&e.floats.at(-1)===t}function $X(e,t){let[n,r]=(0,P.useState)(void 0),i=xX(()=>{r(void 0)}),a=n=>{QX(e,n)||t.focusPane(n)};return{preview:n,raise:a,drag:(n,o,s)=>{s.stopPropagation();let c={mode:n,originX:s.clientX,originY:s.clientY,rect:yJ(gJ(e,o))};i(s.currentTarget,s.pointerId,{move:e=>{r({paneId:o,rect:XX(c,e.clientX,e.clientY)})},up:e=>{let r=XX(c,e.clientX,e.clientY);ZX(r,c.rect)?a(o):n===`move`?t.moveFloat(o,r.x,r.y):t.resizeFloat(o,r)}})}}}function eZ({paneId:e,tab:t,labels:r,intents:i,renderTabTitle:a,canCloseTab:o,drag:s}){return(0,F.jsxs)(`header`,{className:n(kX.tabStrip,kX.floatHeader),"data-dockkit-float-grip":e,onPointerDown:t=>{s(`move`,e,t)},children:[(0,F.jsx)(`div`,{className:n(kX.tab,kX.floatTitle),"data-dockkit-float-title":!0,children:(0,F.jsx)(PX,{children:a?.(t)??t.title})}),(0,F.jsx)(`div`,{className:kX.stripFill}),(0,F.jsx)(hO,{label:r.dockFloat,side:`bottom`,delayMs:500,children:(0,F.jsx)(`button`,{type:`button`,className:kX.iconButton,"aria-label":r.dockFloat,"data-dockkit-float-dock":e,onPointerDown:e=>{e.stopPropagation()},onClick:()=>{i.unfloatPane(e)},children:(0,F.jsx)(te,{className:kX.dockGlyph})})}),(o?.(t.id)??!0)&&(0,F.jsx)(hO,{label:r.closeTab,shortcutKeys:r.closeTabKeys,side:`bottom`,delayMs:500,children:(0,F.jsx)(`button`,{type:`button`,className:kX.iconButton,"aria-label":r.closeTab,"data-dockkit-float-close":e,onPointerDown:e=>{e.stopPropagation()},onClick:()=>{i.closeTab(t.id)},children:(0,F.jsx)(O,{})})})]})}function tZ({state:e,callbacks:t,intents:r,tab:i,pane:a,column:o,floats:s,focusRequest:c,keepMounted:l,active:u=!0}){let d=a.host===`float`,f=d||a.activeTabId===i.id,p=u&&f&&(d||e.expanded),m=l?.(i)??!1,[h,g]=(0,P.useState)(p);p&&!h&&g(!0);let _=(0,P.useRef)(null),v=(0,P.useRef)(null);(0,P.useLayoutEffect)(()=>{let e=_.current;e.inert=!p;let t=document.activeElement;!p&&t instanceof HTMLElement&&e.contains(t)&&t.blur();let n=c.current;p&&n?.tabId===i.id&&(c.current=void 0,(t===null||t===document.body||t===document.documentElement||t===n.origin)&&[...e.querySelector(`[data-dockkit-strip]`)?.querySelectorAll(`[data-dockkit-tab]`)??[]].find(e=>e.dataset.dockkitTab===i.id)?.focus({preventScroll:!0}))},[p,i.id,c]),(0,P.useEffect)(()=>{let n=v.current,r=()=>{p&&(d?s.raise(a.id):e.activePaneId!==a.id&&t.onFocusPane(a.id))};return n.addEventListener(`focus`,r,!0),()=>{n.removeEventListener(`focus`,r,!0)}},[p,d,s,a.id,e.activePaneId,t]);let y=d&&s.preview?.paneId===a.id?s.preview.rect:void 0,b=d?y??yJ(a):void 0,x=y===void 0?e.floats.indexOf(a.id)+1:e.floats.length+1;return(0,F.jsx)(`div`,{className:n(kX.tabCell,d&&kX.floatingCell),hidden:!f,"data-dockkit-host":d?`float`:`dock`,"data-dockkit-column":d?void 0:o,style:{gridColumn:d?1:o*2+1,gridRow:1,order:d?x:0},children:(0,F.jsxs)(`section`,{ref:_,tabIndex:-1,className:n(kX.tabHost,d?kX.float:kX.pane),"aria-hidden":!p||void 0,"data-dockkit-content":i.id,"data-dockkit-pane":!d&&f?a.id:void 0,"data-dockkit-pane-active":!d&&e.activePaneId===a.id||void 0,"data-dockkit-float":d?a.id:void 0,"data-dockkit-float-active":d&&e.activePaneId===a.id||void 0,"data-dockkit-column":d?void 0:o,style:b===void 0?void 0:{left:b.x,top:b.y,width:b.width,height:b.height},onPointerDown:()=>{d&&s.raise(a.id)},onClick:()=>{!d&&e.activePaneId!==a.id&&t.onFocusPane(a.id)},children:[(0,F.jsx)(`div`,{className:kX.tabHostHeader,children:f&&(d?(0,F.jsx)(eZ,{paneId:a.id,tab:i,labels:t.labels,intents:r,renderTabTitle:t.renderTabTitle,canCloseTab:t.canCloseTab,drag:s.drag}):(0,F.jsx)(qX,{state:e,pane:a,callbacks:t}))}),(0,F.jsxs)(`div`,{ref:v,className:n(kX.tabHostBody,d?kX.floatBody:kX.paneBody),children:[h&&(m||u&&f)?t.renderTab(i):null,!d&&(0,F.jsx)(JX,{pane:a,callbacks:t})]}),d&&(0,F.jsx)(`div`,{className:kX.floatResize,"data-dockkit-float-resize":a.id,onPointerDown:e=>{s.drag(`resize`,a.id,e)}})]})})}function nZ(e){let{state:t,callbacks:r,preview:i}=e,a=(0,P.useRef)(void 0),o={...r,onFocusTab:e=>{a.current=CJ(t,e).activeTabId===e?void 0:{tabId:e,origin:document.activeElement},r.onFocusTab(e)}},s=hJ(t,t.rootId);if(s.kind===`split`&&(s.axis!==`row`||s.children.length!==2))throw Error(`DockLayout requires one pane or two horizontally split panes`);let c=s.kind===`pane`?[s]:s.children.map(e=>gJ(t,e)),l=s.kind===`split`?i?.splitId===s.id?i.sizes:s.sizes:[1],u=$X(t,e.intents),d=l.map(e=>`minmax(0, ${e}fr)`).join(` 0px `);return(0,F.jsxs)(`div`,{className:kX.tabLayout,"data-dockkit-split":s.kind===`split`?s.id:void 0,style:{gridTemplateColumns:d},children:[Object.values(t.tabs).sort((e,t)=>e.id.localeCompare(t.id)).map(n=>{let r=CJ(t,n.id);return(0,F.jsx)(tZ,{...e,callbacks:o,tab:n,pane:r,column:c.findIndex(e=>e.id===r.id),floats:u,focusRequest:a},n.id)}),c.filter(e=>e.tabs.length===0).map(e=>(0,F.jsx)(`div`,{className:kX.emptyTabHost,"data-dockkit-empty":!0,style:{gridColumn:c.indexOf(e)*2+1,gridRow:1},children:(0,F.jsx)(YX,{state:t,pane:e,callbacks:r})},e.id)),s.kind===`split`&&(0,F.jsx)(`div`,{className:n(kX.divider,kX.tabLayoutDivider),"data-dockkit-divider":`${s.id}:0`,style:{gridColumn:2,gridRow:1},onPointerDown:e=>{r.onDividerPressed(s.id,0,e)}})]})}var rZ={draggingTabId:void 0,dropTarget:void 0,sizes:void 0},iZ=new Map,aZ=()=>!0;function oZ(e,t,n,r,i,a){for(let[o,s]of fX(e)){let e=s.getBoundingClientRect();if(!kY(e,t,n))continue;let c=s.querySelector(`[data-dockkit-strip]`);if(c!==null&&kY(c.getBoundingClientRect(),t,n))return{kind:`strip`,paneId:o,index:jY([...c.querySelectorAll(`[data-dockkit-tab]`)].map(e=>e.getBoundingClientRect()),t)};let l=a===`horizontal`?r&&_X(i,o).row?t<e.x+e.width/2?`left`:`right`:`center`:AY(e,t,n);if(l!==`center`){let e=_X(i,o),t=l===`left`||l===`right`?e.row:e.column;if(!r||!t)return}return{kind:`zone`,paneId:o,zone:l}}}function sZ(e,t,n,r){let i=(e.axis===`row`?t:n)-e.origin,a=e.extent>0?i/e.extent:0;return OY(FY(e.sizes,e.index,a),r)}var cZ=1e-9;function lZ(e,t){return e.length===t.length&&e.every((e,n)=>{let r=t[n];return r!==void 0&&Math.abs(e-r)<cZ})}function uZ({state:e,canSplit:t,canAddTab:n,canCloseTab:r,intents:i,labels:a,renderTab:o,renderTabTitle:s,renderTabMenuItems:c,chrome:l,onRoom:u,draw:d,dropZones:f=`edges`,minPaneFraction:p=bY,hideSplitWhenBlocked:m=!1}){let h=(0,P.useRef)(null),[g,_]=(0,P.useState)(rZ),[v,y]=(0,P.useState)(iZ),b=xX(()=>{_(rZ)}),x=(0,P.useCallback)(e=>{let t=h.current;t!==null&&e(t)},[]),S=(0,P.useCallback)(()=>{x(e=>{let t=gX(e,m);y(e=>vX(e,t)?e:t)})},[x,m]);(0,P.useLayoutEffect)(()=>{S()}),(0,P.useEffect)(()=>{u?.(v)},[v,u]),(0,P.useEffect)(()=>{let e=h.current;if(e===null||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{S()});return t.observe(e),()=>{t.disconnect()}},[S]);let C={onFocusTab:i.focusTab.bind(i),onFocusPane:i.focusPane.bind(i),onSplitPane:i.splitPane.bind(i),onAddTab:i.addTab.bind(i),onCloseTab:i.closeTab.bind(i),onTabPressed:(e,n)=>{x(r=>{let a=n.clientX,o=n.clientY,s=!1;b(n.currentTarget,n.pointerId,{move:n=>{if(!s){if(!PY(a,o,n.clientX,n.clientY))return;s=!0}_({...rZ,draggingTabId:e,dropTarget:oZ(r,n.clientX,n.clientY,t,v,f)})},up:n=>{if(!s)return;let a=oZ(r,n.clientX,n.clientY,t,v,f);if(a===void 0){if(kY(r.getBoundingClientRect(),n.clientX,n.clientY))return;i.floatTab(e,RY(n.clientX,n.clientY,xY))}else a.kind===`strip`?i.placeTab(e,a.paneId,a.index):i.dropTab(e,a.paneId,a.zone)}})})},onDividerPressed:(t,n,r)=>{let a=r.currentTarget.parentElement;if(a===null)return;let o=_J(e,t),s=a.getBoundingClientRect(),c={splitId:t,index:n,axis:o.axis,origin:o.axis===`row`?r.clientX:r.clientY,extent:o.axis===`row`?s.width:s.height,sizes:o.sizes};b(r.currentTarget,r.pointerId,{move:e=>{_({...rZ,sizes:{splitId:t,sizes:sZ(c,e.clientX,e.clientY,p)}})},up:e=>{let n=sZ(c,e.clientX,e.clientY,p);lZ(n,c.sizes)||i.resizeSplit(t,n)}})},splitBlock:e=>t?_X(v,e).row?void 0:`width`:`budget`,hideSplitWhenBlocked:m,canAddTab:n??aZ,canCloseTab:r??aZ,dropTarget:g.dropTarget,horizontalDrops:f===`horizontal`,draggingTabId:g.draggingTabId,labels:a,renderTab:o,renderTabTitle:s,renderTabMenuItems:c,chromePaneId:LJ(e),chrome:l};return(0,F.jsx)(`div`,{className:kX.surface,ref:h,"data-dockkit-surface":!0,"data-dockkit-drop-zones":f,children:d(C,g.sizes)})}function dZ(e){return(0,F.jsx)(uZ,{...e,draw:(t,n)=>(0,F.jsx)(nZ,{...e,callbacks:t,preview:n})})}var fZ={session:`_session_nj5n1_24`,panel:`_panel_nj5n1_32`,iconButton:`_iconButton_nj5n1_121`,collapseGlyph:`_collapseGlyph_nj5n1_147`,panelBody:`_panelBody_nj5n1_151`,unavailable:`_unavailable_nj5n1_157`,tabTitle:`_tabTitle_nj5n1_165`,tabBody:`_tabBody_nj5n1_169`};function pZ(){return(0,F.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,children:(0,F.jsx)(`path`,{d:`M2.33203 10.4054V13.1681C2.33229 13.444 2.55605 13.6681 2.83203 13.6681H5.49512V14.6681H2.83203C2.00376 14.6681 1.33229 13.9963 1.33203 13.1681V10.4054H2.33203ZM14.6689 13.1681C14.6687 13.996 13.9968 14.6676 13.1689 14.6681H10.4951V13.6681H13.1689C13.4445 13.6676 13.6687 13.4437 13.6689 13.1681V10.4054H14.6689V13.1681ZM13.1689 1.33118C13.9969 1.33163 14.6688 2.00315 14.6689 2.83118V5.4054H13.6689V2.83118C13.6688 2.55544 13.4446 2.33162 13.1689 2.33118H10.4951V1.33118H13.1689ZM5.49512 2.33118H2.83203C2.55598 2.33118 2.33218 2.55516 2.33203 2.83118V5.4054H1.33203V2.83118C1.33218 2.00288 2.00369 1.33118 2.83203 1.33118H5.49512V2.33118Z`,fill:`currentColor`})})}function mZ(){return(0,F.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,children:[(0,F.jsx)(`path`,{d:`M9 2.5V6C9 6.26522 9.10536 6.51957 9.29289 6.70711C9.48043 6.89464 9.73478 7 10 7H13.5`,stroke:`currentColor`}),(0,F.jsx)(`path`,{d:`M7 13.5V10C7 9.73478 6.89464 9.48043 6.70711 9.29289C6.51957 9.10536 6.26522 9 6 9H2.5`,stroke:`currentColor`})]})}function hZ({sessionId:e,fullscreen:t,focus:n=!1,actions:r,t:i,shortcuts:a,toggleFullscreen:o}){let s=t?`push`:`fullscreen`,c=i(n?`chrome.exitFocus`:t?`chrome.exitFullscreen`:`chrome.toFullscreen`),l=a.find(e=>e.id===`pane.fullscreen.toggle`),u=a.find(e=>e.id===`sidebar.right.toggle`);return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(hO,{label:c,shortcutKeys:l?.keys,side:`bottom`,delayMs:500,children:(0,F.jsx)(`button`,{type:`button`,className:fZ.iconButton,"aria-label":c,"aria-keyshortcuts":l?.aria,"data-sidebar-right-mode":s,onClick:o,children:t?(0,F.jsx)(mZ,{}):(0,F.jsx)(pZ,{})})}),(0,F.jsx)(hO,{label:i(`chrome.collapse`),shortcutKeys:u?.keys,side:`bottom`,delayMs:500,children:(0,F.jsx)(`button`,{type:`button`,className:fZ.iconButton,"aria-label":i(`chrome.collapseAria`),"aria-keyshortcuts":u?.aria,"data-sidebar-right-toggle":!0,onClick:()=>{r.toggleExpanded(e)},children:(0,F.jsx)(te,{className:fZ.collapseGlyph})})})]})}function gZ(e,t,n){return{emptyPane:e(`dock.emptyPane`),splitPane:e(`dock.splitPane`),splitPaneShortcut:t?.aria,splitPaneKeys:t?.keys,splitPaneDisabled:e(`dock.splitPaneDisabled`),splitPaneNarrow:e(`dock.splitPaneNarrow`),closeTab:e(`dock.closeTab`),closeTabShortcut:n?.aria,closeTabKeys:n?.keys,addTab:e(`dock.addTab`),dockFloat:e(`dock.dockFloat`),closeFloat:e(`dock.closeFloat`),dropZone:{center:e(`dock.drop.center`),left:e(`dock.drop.left`),right:e(`dock.drop.right`),top:e(`dock.drop.top`),bottom:e(`dock.drop.bottom`)}}}var _Z={"command.close":`关闭当前页面/窗口`,"command.refresh":`刷新当前页面`,"command.noRefresh":`当前页面不支持刷新`,"command.toggle":`展开/收起右侧栏`,"command.fullscreen":`面板全屏/退出全屏`,"command.noSession":`请先选择会话`,"command.noFocus":`请先聚焦右侧面板`,"command.stale":`页面已切换,请重新聚焦`,"command.collapsed":`请先展开右侧栏`,"command.float":`浮动面板不支持此操作`,"command.empty":`请先打开页面`,"command.budget":`已达两格上限`,"command.width":`栏宽不足,拖宽侧边栏后再分栏`,"chrome.expand":`打开侧边栏`,"chrome.expandAria":`打开右侧边栏`,"chrome.collapse":`收起侧边栏`,"chrome.collapseAria":`收起右侧边栏`,"chrome.toFullscreen":`全屏`,"chrome.exitFullscreen":`退出全屏`,"chrome.exitFocus":`退出专注模式`,"dock.emptyPane":`空面板`,"dock.splitPane":`分栏`,"dock.splitPaneDisabled":`已达两格上限`,"dock.splitPaneNarrow":`栏宽不足,拖宽侧边栏后再分栏`,"dock.closeTab":`关闭`,"dock.addTab":`新标签页`,"dock.dockFloat":`收回到侧边栏`,"dock.closeFloat":`关闭`,"dock.drop.center":`移到这里`,"dock.drop.left":`左分栏`,"dock.drop.right":`右分栏`,"dock.drop.top":`上分栏`,"dock.drop.bottom":`下分栏`,"tab.guide.title":`开始`,"tab.unavailable":`这类内容还没有可用的查看方式。`},vZ={"command.close":`Close current page or window`,"command.refresh":`Refresh current page`,"command.noRefresh":`This page cannot be refreshed`,"command.toggle":`Toggle right sidebar`,"command.fullscreen":`Toggle panel fullscreen`,"command.noSession":`Select a session first`,"command.noFocus":`Focus a right sidebar pane first`,"command.stale":`The page changed; focus it again`,"command.collapsed":`Expand the right sidebar first`,"command.float":`This action is unavailable in a floating panel`,"command.empty":`Open a page first`,"command.budget":`Two panes is the limit`,"command.width":`Not enough width to split, widen the sidebar`,"chrome.expand":`Open sidebar`,"chrome.expandAria":`Open right sidebar`,"chrome.collapse":`Collapse sidebar`,"chrome.collapseAria":`Collapse right sidebar`,"chrome.toFullscreen":`Fullscreen`,"chrome.exitFullscreen":`Exit fullscreen`,"chrome.exitFocus":`Exit focus mode`,"dock.emptyPane":`Empty pane`,"dock.splitPane":`Split`,"dock.splitPaneDisabled":`Two panes is the limit`,"dock.splitPaneNarrow":`Not enough width to split, widen the sidebar`,"dock.closeTab":`Close`,"dock.addTab":`New tab`,"dock.dockFloat":`Send back to the sidebar`,"dock.closeFloat":`Close`,"dock.drop.center":`Move here`,"dock.drop.left":`Add left split`,"dock.drop.right":`Add right split`,"dock.drop.top":`Add top split`,"dock.drop.bottom":`Add bottom split`,"tab.guide.title":`Start`,"tab.unavailable":`Nothing here can view this kind of content yet.`},yZ={button:`_button_1rv3m_2`,md:`_md_1rv3m_23`,sm:`_sm_1rv3m_28`,primary:`_primary_1rv3m_36`,ghost:`_ghost_1rv3m_45`,outline:`_outline_1rv3m_54`,toolbar:`_toolbar_1rv3m_63`,icon:`_icon_1rv3m_71`},bZ=(0,P.forwardRef)(function({variant:e=`ghost`,size:t=`md`,icon:r,className:i,children:a,...o},s){return(0,F.jsxs)(`button`,{ref:s,type:`button`,className:n(yZ.button,yZ[e],yZ[t],i),...o,children:[r!=null&&(0,F.jsx)(`span`,{className:yZ.icon,children:r}),a]})}),xZ={button:`_button_11lrx_2`,icon:`_icon_11lrx_15`};function SZ(e,t){if(!e||typeof e!=`object`)throw Error(`Module must default export a plugin definition`);let n=e;if(n.id!==t||n.apiVersion!==1)throw Error(`Plugin id or apiVersion does not match the catalog`);if(typeof n.activate!=`function`)throw Error(`Plugin must declare synchronous activate(context)`);for(let e of[`slots`,`commands`,`menuItems`,`interactions`,`artifactTools`])if(n[e]!==void 0&&!Array.isArray(n[e]))throw Error(`${e} must be an array`);let r=new Set;for(let e of n.slots??[]){if(!e||![`composer.controls`,`turn.tail`,`rightbar.panel`,`rightbar.title`].includes(e.slot)||typeof e.id!=`string`||typeof e.component!=`function`||r.has(e.id))throw Error(`Invalid or duplicate slot`);r.add(e.id)}for(let e of[...n.commands??[],...n.menuItems??[]]){if(!e||typeof e.id!=`string`||typeof e.action!=`string`||r.has(e.id))throw Error(`Invalid or duplicate command/menu contribution`);r.add(e.id)}if((n.commands??[]).some(e=>!u(e)))throw Error(`Invalid command`);let i=new Set;for(let e of n.interactions??[]){if(!e||typeof e.kind!=`string`||!e.kind||i.has(e.kind)||typeof e.component!=`function`)throw Error(`Invalid or duplicate interaction`);i.add(e.kind)}if(n.composerPlaceholder!==void 0&&typeof n.composerPlaceholder!=`function`)throw Error(`Invalid composer placeholder`);if(n.composerAction!==void 0&&typeof n.composerAction!=`function`)throw Error(`Invalid composer action`);if(n.artifactTools?.some(e=>typeof e!=`string`))throw Error(`Invalid artifact tools`);if(n.workbench){let{entry:e,panels:t,toolViews:r,beforeSend:i}=n.workbench;if(i!==void 0&&typeof i!=`function`)throw Error(`Invalid workbench pre-send hook`);if(r!==void 0&&(!Array.isArray(r)||r.some(e=>!e||!Array.isArray(e.tools)||!e.tools.length||e.tools.some(e=>typeof e!=`string`||!e)||typeof e.component!=`function`)))throw Error(`Invalid workbench tool view`);if(n.workbench.resolvePanel!==void 0&&typeof n.workbench.resolvePanel!=`function`)throw Error(`Invalid workbench artifact resolver`);if(n.workbench.apiVersion!==1||!Array.isArray(t)||t.some(e=>typeof e.kind!=`string`||typeof e.component!=`function`)||new Set(t.map(e=>e.kind)).size!==t.length)throw Error(`Invalid workbench contribution`);if(e!==void 0&&(!e||typeof e.kind!=`string`||!e.kind||!p(e.label)||!p(e.description)||e.panelTitle!==void 0&&!p(e.panelTitle)||typeof e.icon!=`function`||!t.some(t=>t.kind===e.kind)))throw Error(`Invalid workbench entry`)}return n}function CZ(e,t,n){return new Promise((r,i)=>{let a,o=()=>s(Error(`Plugin load aborted`)),s=(e,n)=>{clearTimeout(a),t.removeEventListener(`abort`,o),e?i(e):r(n)};t.addEventListener(`abort`,o,{once:!0}),n!==void 0&&(a=setTimeout(()=>s(Error(`Plugin load timed out`)),n)),e.then(e=>s(null,e),e=>s(e)),t.aborted&&o()})}var wZ=class{controller=new AbortController;cleanups=[];disposed=!1;report;constructor(e){this.report=e}context(e){return{sessionId:e,signal:this.controller.signal,onDispose:e=>{if(typeof e!=`function`)throw Error(`onDispose expects a cleanup function`);this.disposed?this.clean(e):this.cleanups.push(e)}}}clean(e){try{e()}catch(e){this.report(e)}}dispose(){if(!this.disposed){this.disposed=!0,this.controller.abort();for(let e of this.cleanups.splice(0).reverse())this.clean(e)}}},TZ=(e,t=null)=>({sessionId:t,generation:e,plugins:[],errors:[],ready:!1}),EZ=class{environment;run=null;snapshot=TZ(0);generation=0;listeners=new Set;constructor(e){this.environment=e}getSnapshot=()=>this.snapshot;subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});update(e){this.snapshot=e;for(let e of this.listeners)e()}error(e,t,n,r){let i=`plugin=${t} session=${e.sessionId} generation=${e.generation} stage=${n}: ${r instanceof Error?r.message:String(r)}`;(this.environment.report??console.error)(i),this.run===e&&this.update({...this.snapshot,errors:[...this.snapshot.errors,i]})}async start(e,t){this.dispose();let n={sessionId:e,generation:++this.generation,controller:new AbortController,scopes:[]};this.run=n,this.update(TZ(n.generation,e));try{let r=await CZ(Promise.resolve().then(t),n.controller.signal);if(this.run!==n)return;for(let e of r.errors)this.error(n,`catalog`,`discover`,e);for(let t of r.plugins){if(this.run!==n)break;let r=new wZ(e=>this.error(n,t.id,`dispose`,e));n.scopes.push(r);let i=r.context(e),a=`load`;try{let e=await CZ(this.environment.loadModule(t.client),n.controller.signal,this.environment.loadTimeoutMs??1e4);if(this.run!==n)break;a=`validate`;let o=SZ(e?.default,t.id);if(t.style&&(a=`style`,await CZ(this.environment.loadStyle(t.style,i.signal).then(e=>{i.onDispose(e)}),n.controller.signal,this.environment.loadTimeoutMs??1e4)),this.run!==n)break;a=`activate`;let s=new Set(this.snapshot.plugins.flatMap(e=>e.definition.workbench?.panels.map(e=>e.kind)??[]));if(o.workbench?.panels.some(e=>s.has(e.kind)))throw Error(`Workbench panel kind already registered`);let c=o.activate(i);if(c!==void 0)throw Promise.resolve(c).catch(e=>this.error(n,t.id,`activate`,e)),Error(`activate must be synchronous and return void`);if(this.run!==n){r.dispose();break}this.update({...this.snapshot,plugins:[...this.snapshot.plugins,{id:t.id,definition:o,instanceId:`${n.generation}/${t.id}`}]})}catch(e){this.run===n&&this.error(n,t.id,a,e),r.dispose()}}}catch(e){this.run===n&&this.error(n,`catalog`,`discover`,e)}this.run===n&&this.update({...this.snapshot,ready:!0})}dispose(){let e=this.run;if(e){this.run=null,e.controller.abort();for(let t of e.scopes.reverse())t.dispose();this.update(TZ(this.generation))}}},DZ={"builtin:@pi-webapp/files":()=>N(()=>import(`./plugin-DJaiYPEQ.js`),__vite__mapDeps([34,2,3,35,36])),"builtin:@pi-webapp/terminal":()=>N(()=>import(`./plugin-DObSoug1.js`),__vite__mapDeps([37,2,3,38])),"builtin:@pi-webapp/git":()=>N(()=>import(`./plugin-3Ib-WXMi.js`),__vite__mapDeps([39,2,3,35,36,40]))};function OZ(e){let t=DZ[e];if(!t)throw Error(`Unknown builtin plugin module`);return t()}function kZ(e,t){return new Promise((n,r)=>{let i=document.createElement(`link`);i.rel=`stylesheet`,i.href=e;let a=()=>{t.removeEventListener(`abort`,o),i.onload=i.onerror=null,i.remove()},o=()=>{a(),r(Error(`Plugin stylesheet aborted`))};t.addEventListener(`abort`,o,{once:!0}),i.onload=()=>{t.removeEventListener(`abort`,o),i.onload=i.onerror=null,n(a)},i.onerror=()=>{a(),r(Error(`Plugin stylesheet failed to load`))},t.aborted?o():document.head.append(i)})}function AZ(e,t,n,r=0){let[i]=(0,P.useState)(()=>new EZ({loadModule:e=>e.startsWith(`builtin:`)?OZ(e):import(e),loadStyle:kZ})),a=(0,P.useSyncExternalStore)(i.subscribe,i.getSnapshot),o=(0,P.useRef)(new Map);a.sessionId&&a.ready&&o.current.set(a.sessionId,a.plugins.filter(e=>e.definition.workbench)),(0,P.useEffect)(()=>{if(e&&t)return globalThis.__PI_WEBAPP_REACT__=P,i.start(t,n),()=>i.dispose()},[i,e,t,r]);let s=e&&a.sessionId===t;return{plugins:s?a.plugins:!e&&t?o.current.get(t)??[]:[],errors:s?a.errors:[]}}var jZ=class extends P.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(e){console.error(`pi-webapp plugin ${this.props.id}:`,e)}render(){return this.state.failed?null:this.props.children}};function MZ(e,t){return{...e,invokeAction:(n,r)=>e.invokePluginAction(t,n,r),resolveInteraction:n=>!e.interaction||e.interaction.pluginId!==t?Promise.reject(Error(`No pending interaction`)):e.resolvePluginInteraction(t,e.interaction.requestId,n)}}function NZ({plugins:e,props:t}){let n=t.session?.interactions?.find(t=>e.some(e=>e.id===t.pluginId&&e.definition.interactions?.some(e=>e.kind===t.kind))),r=e.find(e=>e.id===n?.pluginId),i=r?.definition.interactions?.find(e=>e.kind===n?.kind)?.component;return!n||!r||!i?null:(0,F.jsx)(jZ,{id:r.id,children:(0,F.jsx)(i,{...MZ({...t,interaction:n},r.id)})},`${r.instanceId??r.id}/${n.requestId}`)}function PZ({plugins:e,props:t,call:n,result:r,running:i}){let a=e.flatMap(e=>(e.definition.workbench?.toolViews??[]).map(t=>({plugin:e,view:t}))).find(({view:e})=>e.tools.includes(n.toolName??``));if(!a)return null;let o=a.view.component;return(0,F.jsx)(jZ,{id:a.plugin.id,children:(0,F.jsx)(o,{...MZ(t,a.plugin.id),call:n,result:r,running:i})})}function FZ({plugins:e,slot:t,props:n}){let r=e.flatMap(e=>(e.definition.slots??[]).filter(e=>e.slot===t).map(t=>({plugin:e,item:t})));return r.sort((e,t)=>(e.item.order??0)-(t.item.order??0)||e.plugin.id.localeCompare(t.plugin.id)||e.item.id.localeCompare(t.item.id)),(0,F.jsx)(F.Fragment,{children:r.map(({plugin:e,item:t})=>{let r=t.component;return(0,F.jsx)(jZ,{id:e.id,children:(0,F.jsx)(r,{...MZ(n,e.id)})},`${e.instanceId??e.id}/${t.id}`)})})}function IZ(e,t=[]){let n=(0,P.useRef)(new Map),{controller:r,resources:i,owners:a}=(0,P.useMemo)(()=>{let t=e??``,r=n.current.get(t);if(!r){let e=e=>({id:e,kind:`guide`,contentId:`guide`,title:`开始`});r={controller:new sX({makeInitialTab:e,makePaneTab:e}),resources:new Map,owners:new Map};let i=r;i.controller.subscribe(()=>{let e=i.controller.getSnapshot().state.tabs;for(let[t,n]of i.resources)e[t]||(n.dispose?.(),i.resources.delete(t));for(let t of i.owners.keys())e[t]||i.owners.delete(t)}),n.current.set(t,r)}return r},[e]);(0,P.useEffect)(()=>{for(let[t,r]of n.current)for(let n of r.resources.values())n.activate?.(t===e)},[e]),(0,P.useEffect)(()=>{for(let e of n.current.values())for(let[n,r]of[...e.owners])t.includes(r)&&e.controller.closeTab(n)},[t]),(0,P.useEffect)(()=>()=>{for(let e of n.current.values())for(let t of e.resources.values())t.dispose?.()},[]);let o=(0,P.useSyncExternalStore)(r.subscribe,r.getSnapshot),s=gJ(o.state,o.state.activePaneId).activeTabId,c=s?vJ(o.state,s):void 0;return{controller:r,snapshot:o,panelId:c?.kind===`plugin`?c.contentId:null,resources:i,owners:a,expand:()=>{Object.keys(r.getSnapshot().state.tabs).length||r.openContent({kind:`guide`,contentId:`guide`,title:`开始`}),r.setExpanded(!0)},openContent:(0,P.useCallback)((e,t,n,i,o)=>{let s=r.getSnapshot().state,c=i&&gJ(s,i).host===`dock`?i:GY(s),l=gJ(s,c),u=l.activeTabId&&s.tabs[l.activeTabId]?.kind===`guide`?l.activeTabId:void 0,d=l.tabs.find(n=>s.tabs[n]?.kind===e&&s.tabs[n]?.contentId===t),f=d??r.openContent({kind:e,contentId:t,title:n,paneId:c,revealIfOpened:e!==`files`});return o&&a.set(f,o),d&&r.focusTab(d),u&&r.closeTab(u),r.setExpanded(!0),requestAnimationFrame(()=>document.querySelector(`[data-dockkit-content="${f}"]`)?.focus()),f},[r,a]),shown:o.state.expanded&&Object.keys(o.state.tabs).length>0}}function LZ({panel:e,width:t,narrow:n,focus:i,onExitFocus:a,plugins:o,props:s,cwd:c}){let{controller:l,snapshot:u,openContent:d}=e,{state:f}=u,[p,m]=(0,P.useState)(``),h=(0,P.useRef)(!1),g=(0,P.useMemo)(()=>new Proxy(l,{get(e,t){if(t===`closeTab`)return t=>{if(h.current)return;h.current=!0;let n=s.session?.sessionId??``;op.flush(n).then(async()=>{let r=document.querySelector(`[data-dockkit-content="${CSS.escape(t)}"]`);r&&await op.retireWithin(n,r),m(``),e.closeTab(t)}).catch(e=>m(e instanceof Error?e.message:String(e))).finally(()=>{h.current=!1})};let n=Reflect.get(e,t,e);return typeof n==`function`?n.bind(e):n}}),[l,s.session?.sessionId]),_=n||f.mode===`fullscreen`,v=s.locale===`zh`?_Z:vZ,y=e=>v[e]??e,b=e=>typeof e==`string`?e:e[s.locale],x=o.flatMap(e=>(e.definition.workbench?.panels??[]).map(t=>({plugin:e,contribution:t}))),S=()=>{a(),l.setExpanded(!1),requestAnimationFrame(()=>document.querySelector(`[data-sidebar-right-expand]`)?.focus())},C=n?`100vw`:t;return(0,F.jsx)(`div`,{className:fZ.panel,style:{width:C,"--dsh-sidebar-width":typeof C==`number`?`${C}px`:C},"data-sidebar-right-session":s.session?.sessionId,"data-sidebar-right-panel":_?`fullscreen`:i?`focus`:`push`,"data-sidebar-right-open":e.shown||void 0,"aria-hidden":!e.shown||void 0,children:(0,F.jsxs)(`div`,{className:fZ.panelBody,children:[p&&(0,F.jsx)(`p`,{role:`alert`,children:p}),(0,F.jsx)(dZ,{state:f,canSplit:u.canSplit&&wJ(f).length<2,dropZones:`horizontal`,minPaneFraction:.2,intents:g,labels:gZ(y),active:!0,keepMounted:()=>!0,renderTab:t=>{let n=CJ(f,t.id).id,i=f.expanded&&gJ(f,n).activeTabId===t.id;if(t.kind===`guide`)return(0,F.jsx)(`div`,{className:ue.guide,children:(0,F.jsxs)(`div`,{className:ue.guideGrid,role:`group`,"aria-label":r(`工作区工具`,`Workspace tools`),children:[o.map(e=>{let t=e.definition.workbench?.entry;if(!t)return null;let r=t.icon;return(0,F.jsxs)(`button`,{type:`button`,className:ue.guideEntry,disabled:!s.session||!c,"aria-label":b(t.label),onClick:()=>d(t.kind,t.multiple?ge():`workspace`,b(t.panelTitle??t.label),n,e.id),children:[(0,F.jsx)(`span`,{className:ue.guideIcon,"aria-hidden":`true`,children:(0,F.jsx)(r,{size:24})}),(0,F.jsxs)(`span`,{className:ue.guideCopy,children:[(0,F.jsx)(`span`,{className:ue.guideLabel,children:b(t.label)}),(0,F.jsx)(`span`,{className:ue.guideDescription,children:b(t.description)})]})]},e.id)}),!o.some(e=>e.definition.workbench?.entry)&&(0,F.jsx)(`p`,{className:ue.state,children:r(`没有已启用的工作区插件,可在设置中启用。`,`No workspace plugins enabled. Enable one in Settings.`)})]})});let a=x.find(e=>e.contribution.kind===t.kind);if(a&&s.session){let{plugin:r,contribution:o}=a;e.owners.set(t.id,r.id);let c=o.component;return(0,F.jsx)(jZ,{id:r.id,children:(0,F.jsx)(c,{sendMessage:s.sendMessage,session:s.session,locale:s.locale,visible:i,contentId:t.contentId,title:t.title,renderMarkdown:s.renderMarkdown,resource:(n,r,i)=>{let a=e.resources.get(t.id);if(!a){let o=n();a={value:o,dispose:()=>r?.(o),activate:e=>i?.(o,e)},e.resources.set(t.id,a)}return a.value},open:(e,t,i)=>d(e,t,i,n,r.id)})})}return(0,F.jsx)(FZ,{plugins:o,slot:`rightbar.panel`,props:{...s,panelId:t.contentId}})},renderTabTitle:e=>{if(e.kind===`guide`)return y(`tab.guide.title`);let t=x.find(t=>t.contribution.kind===e.kind);return t?(0,F.jsx)(`span`,{className:ue.title,children:t.contribution.title?.(e.contentId,e.title)??e.title}):(0,F.jsx)(FZ,{plugins:o,slot:`rightbar.title`,props:{...s,panelId:e.contentId}})},chrome:(0,F.jsx)(hZ,{sessionId:s.session?.sessionId??``,fullscreen:_||i,focus:i,shortcuts:[],t:y,actions:{toggleExpanded:S},toggleFullscreen:()=>i?a():n?S():l.setMode(_?`push`:`fullscreen`)})})]})})}function RZ({panel:e,locale:t}){if(e.shown)return null;let n=t===`zh`?_Z:vZ;return(0,F.jsx)(hO,{label:n[`chrome.expand`],side:`bottom`,delayMs:500,children:(0,F.jsx)(bZ,{size:`sm`,className:xZ.button,"aria-label":n[`chrome.expandAria`],"data-sidebar-right-expand":!0,onClick:e.expand,children:(0,F.jsx)(te,{className:xZ.icon})})})}function zZ(e,t){let n=e.filter(e=>e.enabled&&e.generation!==void 0&&e.contribution&&e.documentUrl&&e.controllerUrl).map(e=>{let n=t.find(t=>t.pluginId===e.pluginId);return n&&n.generation===e.generation&&n.name===e.name&&n.icon===e.icon&&n.documentUrl===e.documentUrl&&n.controllerUrl===e.controllerUrl&&JSON.stringify(n.contribution)===JSON.stringify(e.contribution)?n:e});return n.length===t.length&&n.every((e,n)=>e===t[n])?t:n}var BZ=`pi:hosted:unconfirmed-views:v1`,VZ=`pi:hosted:unconfirmed-view:v1:`,HZ=`pi:hosted:retired-view:v1:`,UZ=``,WZ=()=>{UZ=`View recovery journal could not be read. Its original data has been retained.`},GZ=()=>{UZ=`View recovery journal could not be stored. Keep this page open and download local drafts.`};function KZ(e){if(!e||typeof e!=`object`)return!1;let t=e;return[`controller`,`workspace`,`editor`,`tool`].includes(String(t.kind))&&[`sessionId`,`pluginId`,`mountId`,`viewToken`].every(e=>typeof t[e]==`string`&&t[e].length>0&&t[e].length<=214)&&Number.isSafeInteger(t.generation)&&Number(t.generation)>=1&&(t.contentId===void 0||typeof t.contentId==`string`)&&(t.createdAt===void 0||Number.isSafeInteger(t.createdAt))&&[`retained`,`frameStarted`].every(e=>t[e]===void 0||typeof t[e]==`boolean`)&&(t.backups===void 0||Array.isArray(t.backups)&&t.backups.every(e=>e&&typeof e.key==`string`&&typeof e.name==`string`))}function qZ(){try{if(typeof sessionStorage>`u`)return[];let e=sessionStorage.getItem(BZ);if(!e)return[];let t=JSON.parse(e);if(!Array.isArray(t)||!t.every(KZ))throw Error(`Invalid view recovery journal`);return t}catch{return WZ(),[]}}function JZ(e){if(typeof localStorage>`u`)return null;let t=localStorage.getItem(HZ+e);if(t!==null){if(JSON.parse(t)!==!0)throw Error(`Invalid view retirement receipt`);return`retired`}let n=localStorage.getItem(VZ+e);if(!n)return null;let r=JSON.parse(n);if(!KZ(r)||r.viewToken!==e)throw Error(`Invalid durable view recovery record`);return r}function YZ(e,t){return e.sessionId===t.sessionId&&e.pluginId===t.pluginId&&e.generation===t.generation&&e.mountId===t.mountId}var XZ=qZ(),ZZ=new Set(XZ.map(e=>e.viewToken));function QZ(){let e=new Map(XZ.map(e=>[e.viewToken,e]));try{if(typeof localStorage<`u`)for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t),r=n?.startsWith(VZ)?VZ:n?.startsWith(HZ)?HZ:void 0;if(!r)continue;let i=n.slice(r.length);try{let t=JZ(i);if(t===`retired`)e.delete(i);else if(t){let n=e.get(i);if(n&&!YZ(n,t))throw Error(`Conflicting view recovery identity`);e.set(i,{...t,discovered:!ZZ.has(i)})}}catch{WZ()}}}catch{WZ()}return[...e.values()]}var $Z=QZ(),eQ=[...$Z];function tQ(){return eQ=eQ.filter(e=>{try{return JZ(e.viewToken)!==`retired`}catch{return WZ(),!0}}),eQ.filter(e=>$Z.some(t=>t.viewToken===e.viewToken))}var nQ=new Map,rQ=`pi:hosted:recovery-draft:v1:`,iQ=()=>UZ;function aQ(){if(UZ)return!1;try{return typeof sessionStorage<`u`&&sessionStorage.setItem(BZ,JSON.stringify(eQ.filter(e=>ZZ.has(e.viewToken)))),!0}catch{return GZ(),!1}}function oQ(e){if(UZ)return!1;try{if(typeof localStorage>`u`)return!0;let t=JZ(e.viewToken);if(t===`retired`)return!1;if(t&&!YZ(t,e))throw Error(`Conflicting view recovery identity`);let{discovered:n,...r}={...e,...t?.frameStarted?{frameStarted:!0}:{},...t?.retained?{retained:!0}:{},backups:[...new Map([...t?.backups??[],...e.backups??[]].map(e=>[e.key,e])).values()]};return localStorage.setItem(VZ+e.viewToken,JSON.stringify(r)),!0}catch{return GZ(),!1}}function sQ(e,t,n){ZZ.add(t),eQ=eQ.filter(e=>e.viewToken!==t);let r={...e,viewToken:t,kind:n.kind,contentId:n.contentId,frameStarted:!1,createdAt:Date.now()};eQ.push(r),oQ(r),aQ()}function cQ(e){let t=eQ.find(t=>t.viewToken===e);if(!t||t.retained)return!1;let n={...t,frameStarted:!0};return oQ(n)?(eQ=eQ.map(t=>t.viewToken===e?n:t),aQ()):!1}function lQ(e){eQ=eQ.filter(t=>t.viewToken!==e),ZZ.delete(e);try{JZ(e),typeof localStorage<`u`&&localStorage.setItem(HZ+e,JSON.stringify(!0))}catch{WZ()}aQ()}async function uQ(e){if(e.discovered&&(e.kind===`controller`||e.frameStarted!==!0))return;let t=(await qk.view({...e,operation:`reconcile`})).recovery;return t?.state===`unconfirmed`&&e.frameStarted===!1&&ZZ.has(e.viewToken)&&(await qk.view({...e,operation:`cancel-initialization`}),lQ(e.viewToken),t={...t,state:`retired`}),(t?.state===`retired`||t?.state===`absent`&&e.kind===`controller`)&&lQ(e.viewToken),t}var dQ=3e5,fQ=new Set([`invalid_scope`,`unknown_plugin`]),pQ=`@chengzhiyi/pi-excalidraw`;function mQ(e){if(!Array.isArray(e))return;let t=e.filter(e=>e&&typeof e==`object`&&!e.isDeleted).map(e=>[String(e.id),e.version,e.versionNonce]);return JSON.stringify(t.sort((e,t)=>e[0]<t[0]?-1:+(e[0]>t[0])))}async function hQ(e,t){if(e.kind===`controller`)return!0;let n=yQ(e);if(!n.length)return!0;if(e.pluginId!==pQ||t===void 0)return!1;for(let r of n){let n=/^recovery-(.+)\.excalidraw$/.exec(r.name)?.[1];if(!n)return!1;try{let i=await qk.action({sessionId:e.sessionId,pluginId:e.pluginId,generation:t,action:`get`,input:{id:n}}),a=mQ(JSON.parse(r.json).elements);if(!a||a!==mQ(i?.scene?.elements))return!1}catch{return!1}}return!0}async function gQ(e,t,n=Date.now()){if(e.retained)return{state:`retained`};let r=e.frameStarted===!0||e.createdAt===void 0||n-e.createdAt>dQ,i=async()=>await hQ(e,t)?(lQ(e.viewToken),!0):!1,a;try{a=(await qk.view({...e,operation:`status`})).recovery}catch(t){let n=t?.code;if(r&&typeof n==`string`&&fQ.has(n)&&await i())return{state:`retired`};if(t instanceof Error&&t.message===`Unknown view operation`)return uQ(e);throw t}if(a?.state===`retired`)return lQ(e.viewToken),a;if(a?.state===`absent`)return r&&await i()?{state:`retired`}:r||e.discovered?a:uQ(e);if(a?.state===`unconfirmed`&&a.stale){if(e.kind===`controller`)return uQ({...e,discovered:!1});if(!a.dirty&&!a.busy&&await hQ(e,t))try{return await qk.view({...e,operation:`close`}),lQ(e.viewToken),{state:`retired`}}catch{return a}return a}return a?.state===`unconfirmed`&&!e.discovered?uQ(e):a}async function _Q(e){let t=await qk.view({...e,operation:`recover`,confirmation:`retain-unconfirmed-edits`});if(t.recovery?.state===`retired`){lQ(e.viewToken);return}if(!t.recovery||![`retained`,`absent`].includes(t.recovery.state))throw Error(`This view still has an active operation. Its recovery state was preserved.`);eQ=eQ.map(t=>t.viewToken===e.viewToken?{...t,retained:!0}:t);let n=eQ.find(t=>t.viewToken===e.viewToken);n&&oQ(n),aQ()}async function vQ(e){(await qk.view({...e,operation:`reconcile`})).recovery?.state!==`absent`&&await qk.view({...e,operation:`discard`,confirmation:`discard-unconfirmed-edits`}),lQ(e.viewToken)}function yQ(e){if(e.pluginId!==`@chengzhiyi/pi-excalidraw`)return[];let t=`pi-diagram:${e.sessionId}:`,n=[];try{if(typeof localStorage>`u`)return[];for(let t of e.backups??[]){if(!t.key.startsWith(`${rQ}${e.viewToken}:`))continue;let r=nQ.get(t.key)??localStorage.getItem(t.key);r&&n.push({name:t.name,json:r})}if(n.length)return n;for(let r=0;r<localStorage.length;r++){let i=localStorage.key(r);if(!i?.startsWith(t)||e.contentId&&i!==t+e.contentId)continue;let a=localStorage.getItem(i);if(!(!a||a.length>16777216))try{let e=JSON.parse(a);if(!e||!Array.isArray(e.elements))continue;let r=i.slice(t.length).replace(/[^\w.-]/g,`_`).slice(0,100);n.push({name:`recovery-${r}.excalidraw`,json:a})}catch{}}}catch{}return n}for(let e of $Z){if(e.kind===`controller`)continue;let t=yQ(e);t.length&&(e.backups=t.map(t=>{let n=`${rQ}${e.viewToken}:${t.name}`;nQ.set(n,t.json);try{localStorage.getItem(n)||localStorage.setItem(n,t.json)}catch{UZ=`Recovery copy could not be stored. Keep this page open and download local drafts before reloading.`}return{key:n,name:t.name}}))}for(let e of eQ)oQ(e);aQ();function bQ(e){let t=e;if(!t||!(t.blob instanceof Blob)||!t.blob.size||t.blob.size>16777216||typeof t.name!=`string`||t.name.length>200||/[/\\\x00-\x1f\x7f]/.test(t.name))throw Error(`Invalid drawing download`);let n={png:`image/png`,svg:`image/svg+xml`,excalidraw:`application/json`,json:`application/json`}[t.name.split(`.`).pop()?.toLowerCase()??``];if(!n||t.blob.type!==n)throw Error(`Unsupported drawing download`);return{blob:t.blob,name:t.name}}function xQ(e){let{blob:t,name:n}=bQ(e),r=URL.createObjectURL(t),i=document.createElement(`a`);i.href=r,i.download=n,i.hidden=!0,document.body.append(i);try{i.click()}finally{i.remove(),setTimeout(()=>URL.revokeObjectURL(r),3e4)}}var SQ={entry:`_entry_ic7m3_1`,trigger:`_trigger_ic7m3_3`,dialog:`_dialog_ic7m3_5`,content:`_content_ic7m3_8`,list:`_list_ic7m3_10`,item:`_item_ic7m3_11`,error:`_error_ic7m3_14`,history:`_history_ic7m3_20`,actions:`_actions_ic7m3_24`};function CQ({sessionId:e,locale:t,openRecovered:n}){let[r,i]=(0,P.useState)(tQ),[a,o]=(0,P.useState)(!1),[s,c]=(0,P.useState)(null),[l,u]=(0,P.useState)(``),[d,f]=(0,P.useState)(!1),[p,m]=(0,P.useState)(0),h=(e,n)=>t===`zh`?e:n,[g,_]=(0,P.useState)(new Set),[v,y]=(0,P.useState)(new Set),b=r.filter(e=>v.has(e.viewToken)&&!g.has(e.viewToken)),x=iQ(),S=e=>{lQ(e),i(t=>t.filter(t=>t.viewToken!==e))};if((0,P.useEffect)(()=>{o(!1),c(null),u(``)},[e]),(0,P.useEffect)(()=>{let e=!0;return(async()=>{let t=new Map;try{t=new Map((await qk.catalog()).plugins.flatMap(e=>e.generation===void 0?[]:[[e.pluginId,e.generation]]))}catch{}let n=e=>y(t=>new Set(t).add(e));for(let a of r){if(!e)return;try{let r=await gQ(a,t.get(a.pluginId));if(!e)return;r?.state===`retired`||r?.state===`absent`&&a.kind===`controller`?S(a.viewToken):r?.state===`retained`&&i(e=>e.map(e=>e.viewToken===a.viewToken?{...e,retained:!0}:e)),_(e=>{let t=new Set(e);return a.discovered&&r?.state===`unconfirmed`&&r.stale===!1?t.add(a.viewToken):t.delete(a.viewToken),t}),n(a.viewToken)}catch(t){if(!e)return;if(t instanceof Error&&t.message===`Unknown view operation`){y(new Set(r.map(e=>e.viewToken)));return}n(a.viewToken),u(String(t))}}})(),()=>{e=!1}},[e,p]),!b.length&&!x)return null;let C=e=>({controller:h(`后台控制器`,`Controller`),workspace:h(`工作区`,`Workspace`),editor:h(`编辑器`,`Editor`),tool:h(`工具预览`,`Tool preview`)})[e]??h(`插件视图`,`Plugin view`),w=s?.operation===`retain`;return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`div`,{className:SQ.entry,"data-hosted-recovery":!0,children:[(0,F.jsx)(`p`,{children:h(`刷新或关闭窗口后,旧插件视图可能尚未完成保存和关闭确认;部分记录也可能属于仍打开的窗口。请先核对原窗口及备份,再保留失联视图的恢复记录,解除升级等操作的阻塞。`,`After reloading or closing a window, previous plugin views may lack save and close confirmations. Some records may belong to windows still open. Check original windows and backups, then retain disconnected views for recovery to unblock updates and other operations.`)}),(0,F.jsxs)(`button`,{type:`button`,className:SQ.trigger,"aria-haspopup":`dialog`,onClick:()=>o(!0),children:[h(`插件视图恢复`,`Plugin view recovery`),` · `,b.length]})]}),(0,F.jsx)(OO,{open:a,onClose:()=>o(!1),title:h(`检查之前的插件视图`,`Review previous plugin views`),closeLabel:h(`关闭`,`Close`),className:SQ.dialog,footer:(0,F.jsx)(EO,{variant:`outline`,disabled:d,onClick:()=>{u(``),m(e=>e+1)},children:h(`重新检查`,`Check again`)}),children:(0,F.jsxs)(`div`,{className:SQ.content,children:[(0,F.jsx)(`p`,{children:h(`以下列出所有会话中待确认的旧插件视图。请先检查原窗口、编辑器和本地备份,只处理已失联的视图;仍打开的窗口请先正常保存并关闭。`,`These are previous plugin views awaiting confirmation across all sessions. Check original windows, editors and local backups. Only recover disconnected views; save and close windows that remain open first.`)}),(0,F.jsx)(`p`,{children:h(`保留恢复记录会停止旧视图继续写入,不会覆盖当前图稿。丢弃未确认的记录不会保存或恢复图稿,无法找回的最新修改可能永久丢失。`,`Retaining recovery records stops old views writing without overwriting the current drawing. Discarding unconfirmed records does not save or restore a drawing; unrecoverable recent edits may be permanently lost.`)}),(0,F.jsx)(`div`,{className:SQ.list,children:b.map((t,r)=>(0,F.jsxs)(`section`,{className:SQ.item,"data-unconfirmed-view":t.mountId,children:[(0,F.jsxs)(`h3`,{children:[C(t.kind),` `,r+1]}),t.retained&&(0,F.jsx)(`p`,{children:h(`失联视图的恢复记录已保留。插件可继续操作;旧稿是否完整仍需核对。`,`Disconnected view recovery record retained. Plugin operations may continue; the old draft still needs verification.`)}),(0,F.jsxs)(`details`,{children:[(0,F.jsx)(`summary`,{children:h(`视图信息`,`View details`)}),(0,F.jsxs)(`dl`,{children:[(0,F.jsx)(`dt`,{children:h(`会话`,`Session`)}),(0,F.jsx)(`dd`,{children:t.sessionId}),(0,F.jsx)(`dt`,{children:h(`插件`,`Plugin`)}),(0,F.jsx)(`dd`,{children:t.pluginId}),(0,F.jsx)(`dt`,{children:h(`版本代次`,`Generation`)}),(0,F.jsx)(`dd`,{children:t.generation}),(0,F.jsx)(`dt`,{children:h(`视图标识`,`View ID`)}),(0,F.jsx)(`dd`,{children:t.mountId}),t.contentId&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`dt`,{children:h(`内容标识`,`Content ID`)}),(0,F.jsx)(`dd`,{children:t.contentId})]})]})]}),(0,F.jsxs)(`div`,{className:SQ.actions,children:[yQ(t).map(e=>(0,F.jsxs)(EO,{variant:`outline`,disabled:d,onClick:()=>xQ({blob:new Blob([e.json],{type:`application/json`}),name:e.name}),children:[h(`下载本地恢复副本`,`Download local recovery copy`),` · `,e.name]},e.name)),t.contentId&&t.sessionId===e&&n&&(0,F.jsx)(EO,{variant:`outline`,disabled:d,onClick:()=>{o(!1),n(t.contentId)},children:h(`打开图稿并核对备份`,`Open drawing and compare backup`)}),!t.retained&&(0,F.jsx)(EO,{variant:`outline`,disabled:d,onClick:()=>c({item:t,operation:`retain`}),children:h(`保留恢复记录并解除阻塞`,`Retain recovery record and unblock`)}),(0,F.jsx)(EO,{variant:`outline`,disabled:d,onClick:()=>c({item:t,operation:`discard`}),children:h(`丢弃此视图的未确认修改`,`Discard this view's unconfirmed edits`)})]})]},t.viewToken))}),(l||x)&&(0,F.jsxs)(`div`,{role:`alert`,className:SQ.error,children:[h(`未能确认部分视图,请保留恢复记录并重试。`,`Some views could not be verified. Keep their recovery records and retry.`),(0,F.jsxs)(`details`,{children:[(0,F.jsx)(`summary`,{children:h(`诊断信息`,`Diagnostics`)}),l||x]})]})]})}),(0,F.jsx)(OO,{open:!!s&&a,onClose:()=>c(null),title:w?h(`保留此视图用于恢复?`,`Retain this view for recovery?`):h(`丢弃此视图的未确认修改?`,`Discard this view's unconfirmed edits?`),closeLabel:h(`关闭`,`Close`),description:w?h(`请先确认旧视图已失联并核对备份。此操作保留恢复记录和本地副本,停止旧视图继续写入,不会保存、覆盖或丢弃图稿。`,`First confirm the old view is disconnected and review backups. This preserves recovery records and local copies and stops the old view writing, without saving, overwriting or discarding a drawing.`):h(`请先确认原标签页已关闭,并下载可恢复的草稿。此操作不会保存或恢复内容;无法找回的修改可能永久丢失。`,`First confirm the original tab is closed and download any recoverable draft. This does not save or restore content; unrecovered edits may be permanently lost.`),footer:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(EO,{variant:`outline`,disabled:d,onClick:()=>c(null),children:h(`取消`,`Cancel`)}),(0,F.jsx)(EO,{variant:`primary`,disabled:d,onClick:()=>{if(!s||d)return;let{item:e,operation:t}=s;f(!0),u(``),(t===`retain`?_Q(e):vQ(e)).then(()=>{t===`retain`?i(tQ()):S(e.viewToken),c(null)}).catch(e=>{u(String(e)),c(null)}).finally(()=>f(!1))},children:w?h(`保留恢复记录`,`Retain record`):h(`确认丢弃`,`Discard edits`)})]})})]})}var wQ=new class{entries=new Set;releaseLock;timer;running=!1;interval;request;constructor(e=250,t=async e=>{let t=new AbortController,n=setTimeout(()=>t.abort(),5e3);try{return await Kk(`/views`,{operation:`pollMany`,views:e},t.signal)}finally{clearTimeout(n)}}){this.interval=e,this.request=t}add(e){return this.entries.add(e),this.holdLock(),this.schedule(0),()=>{this.entries.delete(e),this.entries.size||(this.timer&&=(clearTimeout(this.timer),void 0),this.releaseLock?.())}}holdLock(){if(this.releaseLock||typeof navigator>`u`||!navigator.locks)return;let e,t=new Promise(t=>{e=t});this.releaseLock=()=>{this.releaseLock=void 0,e()},navigator.locks.request(`pi:hosted:view-poller:${crypto.randomUUID()}`,()=>t).catch(()=>{this.releaseLock=void 0})}wake(){!this.running&&this.entries.size&&(this.timer&&=(clearTimeout(this.timer),void 0),this.schedule(0))}schedule(e){this.running||this.timer||!this.entries.size||(this.timer=setTimeout(()=>{this.timer=void 0,this.tick()},e))}async tick(){this.running=!0;let e=[...this.entries];try{for(let t=0;t<e.length;t+=64){let n=e.slice(t,t+64).filter(e=>this.entries.has(e));if(!n.length)continue;let{replies:r}=await this.request(n.map(e=>e.input()));if(!Array.isArray(r)||r.length!==n.length)throw Error(`Invalid aggregate view reply`);await Promise.all(n.map(async(e,t)=>{if(this.entries.has(e))try{let n=r[t];if(n.failure)throw Object.assign(Error(n.failure.body.error),{status:n.failure.status});if(!n.reply||n.reply.viewToken!==e.input().viewToken)throw Error(`Mismatched view reply`);await e.accept(n.reply)}catch(t){this.entries.delete(e),e.fail(t)}}))}}catch(t){for(let n of e)this.entries.delete(n)&&n.fail(t)}finally{this.running=!1,this.schedule(this.interval)}}};typeof document<`u`&&document.addEventListener(`visibilitychange`,()=>{document.hidden||wQ.wake()});var TQ=class{token=``;get capability(){return{viewToken:this.token,mountId:this.identity.mountId}}stopped=!1;closed=!1;closing;abort=new AbortController;unlisten;after=0;snapshot;frozen=!1;localCloseCheckpoint=!1;frameStarted=!1;connecting(){if(!cQ(this.token)&&this.mount.kind!==`controller`)throw Error(`Cannot protect the editor recovery journal; download local drafts before opening another editor`);this.frameStarted=!0}async flushed(){await this.changed({dirty:!1,busy:!1})}identity;adapter;mount;reconnect;failed;poller;constructor(e,t,n,r,i,a=wQ){this.poller=a,this.identity=e,this.adapter=t,this.mount=n,this.reconnect=r,this.failed=i}async start(){this.token=crypto.randomUUID(),sQ(this.identity,this.token,this.mount);let e=await qk.view({...this.identity,operation:`register`,kind:this.mount.kind,viewToken:this.token});e.viewToken!==this.token&&(lQ(this.token),this.token=e.viewToken,sQ(this.identity,this.token,this.mount))}listen(){this.stopped||this.unlisten||(this.unlisten=this.poller.add({input:()=>({...this.identity,viewToken:this.token,operation:`poll`,after:this.after}),accept:e=>this.receive(e),fail:e=>{this.stopped||this.failed(e)}}))}retry(){if(this.closed)throw Error(`Closed view cannot reconnect`);this.unlisten?.(),this.unlisten=void 0,this.stopped=!1,this.abort=new AbortController,this.localCloseCheckpoint?this.adapter.call(`restore`,this.snapshot).then(()=>{this.frozen=!1,this.localCloseCheckpoint=!1,this.listen()}).catch(this.failed):this.listen()}request(e){return qk.view({...this.identity,viewToken:this.token,...e},this.abort.signal)}async changed(e){let t=e;if(typeof t?.dirty!=`boolean`||typeof t.busy!=`boolean`)throw Error(`Invalid frame status`);await this.request({operation:`change`,dirty:t.dirty,busy:t.busy})}async receive(e){for(let t of e.commands){if(this.stopped)return;let e;try{if(t.type===`freeze`&&!this.frozen&&(this.snapshot=await this.adapter.call(`freeze`),this.frozen=!0),t.type===`resume`&&this.frozen&&(await this.adapter.call(`restore`,this.snapshot),this.frozen=!1),t.type===`committed`){await this.request({operation:`ack`,commandId:t.id,ok:!0}),await this.close(),this.reconnect();return}}catch(t){e=t}await this.request({operation:`ack`,commandId:t.id,ok:!e,...e?{error:e instanceof Error?e.message:String(e)}:{}}),this.after=t.id,e&&this.failed(e)}}close(){return this.closed?Promise.resolve():(this.closing||=(this.stopped=!0,this.unlisten?.(),this.abort.abort(),(async()=>{this.token&&(this.mount.kind!==`controller`&&!this.frameStarted?await qk.view({...this.identity,viewToken:this.token,operation:`cancel-initialization`}):(this.mount.kind!==`controller`&&!this.frozen&&(this.snapshot=await this.adapter.call(`freeze`),this.frozen=!0,this.localCloseCheckpoint=!0),this.localCloseCheckpoint&&await qk.view({...this.identity,viewToken:this.token,operation:`change`,dirty:!1,busy:!1}),await qk.view({...this.identity,viewToken:this.token,operation:`close`})),this.closed=!0,lQ(this.token))})().catch(e=>{throw this.closing=void 0,e})),this.closing)}},EQ={card:`_card_1g0je_1`,header:`_header_1g0je_2`,toggle:`_toggle_1g0je_6`,title:`_title_1g0je_7`,status:`_status_1g0je_8`,chevron:`_chevron_1g0je_9`,parameters:`_parameters_1g0je_12`,preview:`_preview_1g0je_13`,dialog:`_dialog_1g0je_15`,details:`_details_1g0je_18`};function DQ({title:e,tool:t,locale:n,children:r}){let[i,a]=(0,P.useState)(!1),[o,s]=(0,P.useState)(!1),c=(0,P.useId)(),l=(e,t)=>n===`zh`?e:t,u=t.result?.blocks.filter(e=>e.kind===`text`).map(e=>e.text??``).join(`
|
|
500
|
+
`,c),this.lastText=e,this.lastRendered=s,this.lastRendered}},pJ=(0,P.memo)(function({text:e,streaming:t=!1,labels:r,fileMentions:i,pathImages:a,variant:o=`body`}){let s=(0,P.useRef)(null),c=(0,P.useRef)(r),l=(0,P.useMemo)(()=>t?((s.current===null||c.current!==r)&&(s.current=new fJ(r),c.current=r),s.current.render(e)):(s.current=null,dJ(e,r,i,a)),[e,t,r,i,a]);return(0,F.jsx)(`div`,{className:n(Mq.markdown,o===`compact`&&Mq.compact),"data-markdown-variant":o===`compact`?o:void 0,children:l})});function mJ(e,t){throw Error(`${t}: unhandled ${JSON.stringify(e)}`)}function hJ(e,t){let n=e.nodes[t];if(n===void 0)throw Error(`layout: unknown node ${t}`);return n}function gJ(e,t){let n=hJ(e,t);if(n.kind!==`pane`)throw Error(`layout: ${t} is not a pane`);return n}function _J(e,t){let n=hJ(e,t);if(n.kind!==`split`)throw Error(`layout: ${t} is not a split`);return n}function vJ(e,t){let n=e.tabs[t];if(n===void 0)throw Error(`layout: unknown tab ${t}`);return n}function yJ(e){if(e.host!==`float`||e.rect===void 0)throw Error(`layout: ${e.id} is not floating`);return e.rect}function bJ(e,t){let n=e.floats.indexOf(t);if(n<0)throw Error(`layout: floating pane ${t} is not in the z order`);return n}function xJ(e){let t=e.tabs[0];if(t===void 0||e.tabs.length!==1)throw Error(`layout: ${e.id} does not hold exactly one tab`);return t}function SJ(e,t){for(let n of Object.values(e.nodes))if(n.kind===`split`&&n.children.includes(t))return n}function CJ(e,t){for(let n of Object.values(e.nodes))if(n.kind===`pane`&&n.tabs.includes(t))return n;throw Error(`layout: tab ${t} has no pane`)}function wJ(e){let t=[],n=r=>{let i=hJ(e,r);if(i.kind===`pane`)t.push(i.id);else for(let e of i.children)n(e)};return n(e.rootId),t}function TJ(e){let t=e.reduce((e,t)=>e+t,0);if(!(t>0))throw Error(`layout: sizes must sum above zero`);return Math.abs(t-1)<1e-12?[...e]:e.map(e=>e/t)}function EJ(e){return Object.entries(e)}function DJ(e){return Object.keys(e)}function OJ(e,t){let n={};for(let[r,i]of EJ(e.nodes))r in t||(n[r]=i);for(let[e,r]of EJ(t))r!==null&&(n[e]=r);return{...e,nodes:n}}function kJ(e,t){let n={};for(let[r,i]of EJ(e.tabs))r in t||(n[r]=i);for(let[e,r]of EJ(t))r!==null&&(n[e]=r);return{...e,tabs:n}}function AJ(e,t,n){let r=Math.max(0,Math.min(t,e.length));return[...e.slice(0,r),n,...e.slice(r)]}function jJ(e,t){return[...e.slice(0,t),...e.slice(t+1)]}function MJ(e,t){let n=jJ(e,t);if(n.length!==0)return n[Math.max(0,t-1)]}function NJ(e,t,n){return{...e,tabs:t,activeTabId:n}}function PJ(e,t,n){let r=SJ(e,t);if(r===void 0){if(e.rootId!==t)throw Error(`layout: ${t} is neither rooted nor parented`);return{...e,rootId:n}}let i=r.children.map(e=>e===t?n:e);return OJ(e,{[r.id]:{...r,children:i}})}function FJ(e,t){let n=hJ(e,e.rootId);for(;n.kind===`split`;){let r=t(n);if(r===void 0)throw Error(`layout: split ${n.id} has no children`);n=hJ(e,r)}return n.id}function IJ(e){return FJ(e,e=>e.children[0])}function LJ(e){return FJ(e,e=>e.axis===`row`?e.children.at(-1):e.children[0])}function RJ(e,t){let n={};for(let r of t)n[r]=gJ(e,r).activeTabId;return{type:`restoreFocus`,activePaneId:e.activePaneId,floats:e.floats,paneActiveTabs:n}}function zJ(e,t){return[...e.filter(e=>e!==t),t]}function BJ(e,t){return e.activePaneId===t?{...e,activePaneId:IJ(e)}:e}function VJ(e){return{kind:`pane`,id:e,host:`dock`,tabs:[],activeTabId:void 0,rect:void 0}}function HJ(e,t){if(e.nodes[t]!==void 0)throw Error(`layout: node ${t} already exists`)}function UJ(e,t){if(e.tabs[t]!==void 0)throw Error(`layout: tab ${t} already exists`)}function WJ(e,t){if(gJ(e,t.paneId).host!==`dock`)throw Error(`layout: split requires a docked pane`);HJ(e,t.newPaneId);let n=VJ(t.newPaneId),r=SJ(e,t.paneId);if(r!==void 0&&r.axis===t.axis){let i=r.children.indexOf(t.paneId),a=t.direction===`after`?i+1:i,o=AJ(r.children,a,t.newPaneId),s=r.sizes.flatMap((e,t)=>t===i?[e/2,e/2]:[e]);return{state:OJ(e,{[t.newPaneId]:n,[r.id]:{...r,children:o,sizes:s}}),inverse:[{type:`merge`,paneId:t.newPaneId},{type:`resize`,splitId:r.id,sizes:r.sizes}]}}HJ(e,t.newSplitId);let i=PJ(e,t.paneId,t.newSplitId),a=t.direction===`after`?[t.paneId,t.newPaneId]:[t.newPaneId,t.paneId];return{state:OJ(i,{[t.newPaneId]:n,[t.newSplitId]:{kind:`split`,id:t.newSplitId,axis:t.axis,children:a,sizes:[.5,.5]}}),inverse:[{type:`merge`,paneId:t.newPaneId}]}}function GJ(e,t){let n=gJ(e,t.paneId);if(n.tabs.length>0)throw Error(`layout: merge requires an empty pane`);let r=RJ(e,[]);if(n.host===`float`){let i=bJ(e,t.paneId);return{state:BJ(OJ({...e,floats:jJ(e.floats,i)},{[t.paneId]:null}),t.paneId),inverse:[{type:`insertPane`,pane:n,tabs:[],attach:{mode:`float`,index:i}},r]}}let i=SJ(e,t.paneId);if(i===void 0)throw Error(`layout: the docked root pane cannot be merged`);let a=i.children.indexOf(t.paneId);if(i.children.length>2){let o=jJ(i.children,a),s=TJ(jJ(i.sizes,a));return{state:BJ(OJ(e,{[t.paneId]:null,[i.id]:{...i,children:o,sizes:s}}),t.paneId),inverse:[{type:`insertPane`,pane:n,tabs:[],attach:{mode:`child`,parentId:i.id,index:a,sizes:i.sizes}},r]}}let o=i.children[1-a];if(o===void 0)throw Error(`layout: merge found a split without a sibling`);return{state:BJ(OJ(PJ(e,i.id,o),{[t.paneId]:null,[i.id]:null}),t.paneId),inverse:[{type:`insertPane`,pane:n,tabs:[],attach:{mode:`wrap`,targetId:o,split:i}},r]}}function KJ(e,t){let n=gJ(e,t.paneId);if(n.host!==`dock`)throw Error(`layout: openTab requires a docked pane`);UJ(e,t.tab.id);let r=RJ(e,[n.id]);return{state:{...OJ(kJ(e,{[t.tab.id]:t.tab}),{[n.id]:NJ(n,AJ(n.tabs,t.index,t.tab.id),t.tab.id)}),activePaneId:n.id},inverse:[{type:`closeTab`,tabId:t.tab.id},r]}}function qJ(e,t){let n=gJ(e,t.paneId);if(n.host!==`dock`)throw Error(`layout: insertTab requires a docked pane`);UJ(e,t.tab.id);let r=RJ(e,[n.id]),i=AJ(n.tabs,t.index,t.tab.id);return{state:OJ(kJ(e,{[t.tab.id]:t.tab}),{[n.id]:NJ(n,i,n.activeTabId??t.tab.id)}),inverse:[{type:`closeTab`,tabId:t.tab.id},r]}}function JJ(e,t){let n=vJ(e,t.tabId),r=CJ(e,t.tabId),i=r.tabs.indexOf(t.tabId),a=RJ(e,[r.id]);if(r.host===`float`){let i=bJ(e,r.id);return{state:BJ(kJ(OJ({...e,floats:jJ(e.floats,i)},{[r.id]:null}),{[t.tabId]:null}),r.id),inverse:[{type:`insertPane`,pane:r,tabs:[n],attach:{mode:`float`,index:i}},a]}}let o=r.activeTabId===t.tabId?MJ(r.tabs,i):r.activeTabId;return{state:kJ(OJ(e,{[r.id]:NJ(r,jJ(r.tabs,i),o)}),{[t.tabId]:null}),inverse:[{type:`insertTab`,paneId:r.id,tab:n,index:i},a]}}function YJ(e,t){if(HJ(e,t.pane.id),t.pane.tabs.length!==t.tabs.length)throw Error(`layout: insertPane tab records do not match the pane`);if(t.pane.host===`dock`&&t.tabs.length>0)throw Error(`layout: insertPane returns a docked pane empty`);let n={};for(let r of t.tabs)UJ(e,r.id),n[r.id]=r;let r=t.tabs[0],i=r===void 0?[{type:`merge`,paneId:t.pane.id}]:[{type:`closeTab`,tabId:r.id},RJ(e,[])],a=t.attach;switch(a.mode){case`child`:{let r=_J(e,a.parentId),o=AJ(r.children,a.index,t.pane.id);if(a.sizes.length!==o.length)throw Error(`layout: insertPane sizes do not match the split`);return i.push({type:`resize`,splitId:r.id,sizes:r.sizes}),{state:OJ(kJ(e,n),{[t.pane.id]:t.pane,[r.id]:{...r,children:o,sizes:a.sizes}}),inverse:i}}case`wrap`:if(!a.split.children.includes(t.pane.id))throw Error(`layout: insertPane wrap split does not list the pane`);return{state:OJ(kJ(PJ(e,a.targetId,a.split.id),n),{[t.pane.id]:t.pane,[a.split.id]:a.split}),inverse:i};case`float`:{if(t.pane.host!==`float`)throw Error(`layout: float attachment requires a floating pane`);let r=AJ(e.floats,a.index,t.pane.id);return{state:OJ(kJ({...e,floats:r},n),{[t.pane.id]:t.pane}),inverse:i}}default:return mJ(a,`layout: insertPane attachment`)}}function XJ(e,t){let n=CJ(e,t.tabId);if(n.host!==`dock`)throw Error(`layout: moveTab source must be docked; use unfloat`);let r=gJ(e,t.toPaneId);if(r.host!==`dock`)throw Error(`layout: moveTab target must be docked`);if(r.id===n.id)throw Error(`layout: moveTab across one pane; use reorderTab`);let i=n.tabs.indexOf(t.tabId),a=RJ(e,[n.id,r.id]),o=n.activeTabId===t.tabId?MJ(n.tabs,i):n.activeTabId;return{state:{...OJ(e,{[n.id]:NJ(n,jJ(n.tabs,i),o),[r.id]:NJ(r,AJ(r.tabs,t.index,t.tabId),t.tabId)}),activePaneId:r.id},inverse:[{type:`moveTab`,tabId:t.tabId,toPaneId:n.id,index:i},a]}}function ZJ(e,t){let n=CJ(e,t.tabId),r=n.tabs.indexOf(t.tabId),i=AJ(jJ(n.tabs,r),t.index,t.tabId);return{state:OJ(e,{[n.id]:{...n,tabs:i}}),inverse:[{type:`reorderTab`,tabId:t.tabId,index:r}]}}function QJ(e,t){let n=CJ(e,t.tabId),r=RJ(e,[n.id]),i=OJ(e,{[n.id]:{...n,activeTabId:t.tabId}}),a=n.host===`float`?zJ(i.floats,n.id):i.floats;return{state:{...i,activePaneId:n.id,floats:a},inverse:[r]}}function $J(e,t){let n=gJ(e,t.paneId),r=RJ(e,[]),i=n.host===`float`?zJ(e.floats,n.id):e.floats;return{state:{...e,activePaneId:n.id,floats:i},inverse:[r]}}function eY(e,t){let n=_J(e,t.splitId);if(t.sizes.length!==n.children.length)throw Error(`layout: resize sizes do not match the split`);if(t.sizes.some(e=>!(e>0)))throw Error(`layout: resize sizes must all be above zero`);return{state:OJ(e,{[n.id]:{...n,sizes:TJ(t.sizes)}}),inverse:[{type:`resize`,splitId:n.id,sizes:n.sizes}]}}function tY(e,t){vJ(e,t.tabId);let n=CJ(e,t.tabId);if(n.host!==`dock`)throw Error(`layout: float requires a docked tab`);HJ(e,t.newPaneId);let r=n.tabs.indexOf(t.tabId),i=RJ(e,[n.id]),a=n.activeTabId===t.tabId?MJ(n.tabs,r):n.activeTabId,o=OJ(e,{[n.id]:NJ(n,jJ(n.tabs,r),a),[t.newPaneId]:{kind:`pane`,id:t.newPaneId,host:`float`,tabs:[t.tabId],activeTabId:t.tabId,rect:t.rect}});return{state:{...o,floats:[...o.floats,t.newPaneId],activePaneId:t.newPaneId},inverse:[{type:`unfloat`,paneId:t.newPaneId,toPaneId:n.id,index:r},i]}}function nY(e,t){let n=gJ(e,t.paneId),r=yJ(n),i=xJ(n),a=gJ(e,t.toPaneId);if(a.host!==`dock`)throw Error(`layout: unfloat target must be docked`);let o=RJ(e,[a.id]);return{state:{...OJ({...e,floats:jJ(e.floats,bJ(e,t.paneId))},{[t.paneId]:null,[a.id]:NJ(a,AJ(a.tabs,t.index,i),i)}),activePaneId:a.id},inverse:[{type:`float`,tabId:i,newPaneId:t.paneId,rect:r},o]}}function rY(e,t,n){let r=OJ(e,{[t.id]:{...t,rect:n}});return{...r,activePaneId:t.id,floats:zJ(r.floats,t.id)}}function iY(e,t){let n=gJ(e,t.paneId),r=yJ(n);return{state:rY(e,n,{...r,x:t.x,y:t.y}),inverse:[{type:`moveFloat`,paneId:t.paneId,x:r.x,y:r.y},RJ(e,[])]}}function aY(e,t){let n=gJ(e,t.paneId),r=yJ(n);if(!(t.rect.width>0)||!(t.rect.height>0))throw Error(`layout: float size must be above zero`);return{state:rY(e,n,t.rect),inverse:[{type:`resizeFloat`,paneId:t.paneId,rect:r},RJ(e,[])]}}function oY(e,t){let n=RJ(e,DJ(t.paneActiveTabs));for(let n of t.floats)if(gJ(e,n).host!==`float`)throw Error(`layout: restoreFocus lists docked pane ${n} as floating`);let r=e;for(let[e,n]of EJ(t.paneActiveTabs)){let t=gJ(r,e);r=OJ(r,{[e]:{...t,activeTabId:n}})}return gJ(r,t.activePaneId),{state:{...r,activePaneId:t.activePaneId,floats:t.floats},inverse:[n]}}function sY(e,t){switch(t.type){case`split`:return WJ(e,t);case`merge`:return GJ(e,t);case`openTab`:return KJ(e,t);case`insertTab`:return qJ(e,t);case`closeTab`:return JJ(e,t);case`insertPane`:return YJ(e,t);case`moveTab`:return XJ(e,t);case`reorderTab`:return ZJ(e,t);case`focusTab`:return QJ(e,t);case`focusPane`:return $J(e,t);case`resize`:return eY(e,t);case`float`:return tY(e,t);case`unfloat`:return nY(e,t);case`moveFloat`:return iY(e,t);case`resizeFloat`:return aY(e,t);case`setExpanded`:return{state:{...e,expanded:t.expanded},inverse:[{type:`setExpanded`,expanded:e.expanded}]};case`setMode`:return{state:{...e,mode:t.mode},inverse:[{type:`setMode`,mode:e.mode}]};case`restoreFocus`:return oY(e,t);default:return mJ(t,`layout: operation`)}}function cY(e,t){return t.reduce((e,t)=>sY(e,t).state,e)}var lY={entries:[],cursor:0},uY=new Set([`focusTab`,`focusPane`,`restoreFocus`]);function dY(e){return uY.has(e.type)}function fY(e,t){let n=e.entries[t];return n!==void 0&&n.ops.every(dY)}function pY(e){return e.cursor>0}function mY(e){return e.cursor<e.entries.length}function hY(e){return e.entries.flatMap(e=>e.ops)}function gY(e,t,n){if(n.length===0)return{history:e,state:t};let r=t,i=[];for(let e of n){let t=sY(r,e);r=t.state,i.unshift(...t.inverse)}return{history:{entries:[...e.cursor===e.entries.length?e.entries:e.entries.slice(0,e.cursor),{ops:n,inverse:i}],cursor:e.cursor+1},state:r}}function _Y(e,t){if(!pY(e))return;let n=1;if(fY(e,e.cursor-1))for(;fY(e,e.cursor-1-n);)n+=1;let r=t;for(let t of e.entries.slice(e.cursor-n,e.cursor).reverse())for(let e of t.inverse)r=sY(r,e).state;return{history:{entries:e.entries,cursor:e.cursor-n},state:r}}function vY(e,t){if(!mY(e))return;let n=1;if(fY(e,e.cursor))for(;fY(e,e.cursor+n);)n+=1;let r=t;for(let t of e.entries.slice(e.cursor,e.cursor+n))for(let e of t.ops)r=sY(r,e).state;return{history:{entries:e.entries,cursor:e.cursor+n},state:r}}var yY=class{current;recorded=lY;constructor(e){this.current=e}get state(){return this.current}get history(){return this.recorded}get ops(){return hY(this.recorded)}get cursor(){return this.recorded.cursor}get canUndo(){return pY(this.recorded)}get canRedo(){return mY(this.recorded)}dispatch(e){return this.dispatchAll([e])}dispatchAll(e){let t=gY(this.recorded,this.current,e);return this.recorded=t.history,this.current=t.state,this.current}undo(){let e=_Y(this.recorded,this.current);return e!==void 0&&(this.recorded=e.history,this.current=e.state,!0)}redo(){let e=vY(this.recorded,this.current);return e!==void 0&&(this.recorded=e.history,this.current=e.state,!0)}},bY=.12,xY={width:380,height:300},SY={width:220,height:140},CY=.25;function wY(e){return wJ(e).length}function TY(e){return wY(e)<4}function EY(e,t,n=CY){let r=`left`,i=e;return 1-e<i&&(r=`right`,i=1-e),t<i&&(r=`top`,i=t),1-t<i&&(r=`bottom`,i=1-t),i<n?r:`center`}function DY(e){switch(e){case`center`:return;case`left`:return{axis:`row`,direction:`before`};case`right`:return{axis:`row`,direction:`after`};case`top`:return{axis:`column`,direction:`before`};case`bottom`:return{axis:`column`,direction:`after`};default:return mJ(e,`layout: dock zone`)}}function OY(e,t=bY){if(e.length===0)return[];let n=Math.min(t,1/e.length),r=e.map(e=>e>0?e:0),i=r.reduce((e,t)=>e+t,0),a=i>0?r.map(e=>e/i):r.map(()=>1/e.length),o=new Set;for(;;){let e=a.flatMap((e,t)=>!o.has(t)&&e<n?[t]:[]);if(e.length===0)return a;for(let t of e)o.add(t);let t=1-o.size*n,r=a.reduce((e,t,n)=>o.has(n)?e:e+t,0);a=a.map((e,i)=>o.has(i)?n:e/r*t)}}function kY(e,t,n){return t>=e.x&&t<=e.x+e.width&&n>=e.y&&n<=e.y+e.height}function AY(e,t,n,r=CY){return!(e.width>0)||!(e.height>0)?`center`:EY((t-e.x)/e.width,(n-e.y)/e.height,r)}function jY(e,t){let n=0;for(let r of e){if(t<r.x+r.width/2)break;n+=1}return n}var MY={divider:0,chip:100,body:48};function NY(e,t=MY){let{pane:n,strip:r}=e;if(!(n.width>0)||!(n.height>0)||!(r.width>0))return{row:!0,column:!0};let i=Math.max(0,n.width-r.width),a=Math.max(0,r.width-e.chipsWidth-e.fillWidth-(e.splitControlWidth??0)),o=(n.width-t.divider)/2-i,s=(n.height-t.divider)/2-i;return{row:o>=a+t.chip,column:s>=r.height+t.body}}function PY(e,t,n,r){return Math.abs(n-e)>=4||Math.abs(r-t)>=4}function FY(e,t,n){let r=e[t],i=e[t+1];if(r===void 0||i===void 0)return[...e];let a=[...e];return a[t]=r+n,a[t+1]=i-n,a}function IY(e,t,n){return{...e,x:e.x+t,y:e.y+n}}function LY(e,t,n,r){return{...e,width:Math.max(r.width,e.width+t),height:Math.max(r.height,e.height+n)}}function RY(e,t,n){return{x:Math.max(0,e-zY.x),y:Math.max(0,t-zY.y),...n}}var zY={x:60,y:14},BY=24,VY={x:160,y:120},HY=[];function UY(e,t,n,r){for(let i of gJ(e,t).tabs){let t=e.tabs[i];if(t?.contentId===n&&(r===void 0||t.kind===r))return i}}function WY(e,t,n){for(let r of[...wJ(e),...e.floats]){let i=UY(e,r,t,n);if(i!==void 0)return i}}function GY(e){let t=gJ(e,e.activePaneId);return t.host===`dock`?t.id:IJ(e)}function KY(e,t,n,r){return e.host===`float`?{type:`unfloat`,paneId:e.id,toPaneId:n,index:r}:{type:`moveTab`,tabId:t,toPaneId:n,index:r}}function qY(e,t){return e.expanded===t?HY:[{type:`setExpanded`,expanded:t}]}function JY(e,t){return e.mode===t?HY:[{type:`setMode`,mode:t}]}function YY(e,t,n,r){if(!TY(e))return HY;let i=n??GY(e);if(gJ(e,i).host!==`dock`)return HY;let a=t(`pane`),o=[{type:`split`,paneId:i,axis:`row`,direction:`after`,newPaneId:a,newSplitId:t(`split`)}],s=r?.(t(`tab`));return s!==void 0&&o.push({type:`openTab`,paneId:a,tab:s,index:0}),o}function XY(e,t,n,r){if(r===void 0)return HY;let i=gJ(e,n);return i.host===`dock`?[{type:`openTab`,paneId:n,tab:r(t(`tab`)),index:i.tabs.length}]:HY}function ZY(e,t,n){let r=n.revealIfOpened===!1?void 0:WY(e,n.contentId,n.kind);if(r!==void 0)return{ops:[{type:`focusTab`,tabId:r}],tabId:r};let i=n.paneId??GY(e),a={id:t(`tab`),kind:n.kind,contentId:n.contentId,title:n.title};return{ops:[{type:`openTab`,paneId:i,tab:a,index:n.index??gJ(e,i).tabs.length}],tabId:a.id}}function QY(e,t,n){let r=vJ(e,n),i=CJ(e,n),a=i.host===`dock`?i.id:GY(e),o=i.host===`dock`?i.tabs.indexOf(n)+1:gJ(e,a).tabs.length,s={...r,id:t(`tab`)};return{ops:[{type:`openTab`,paneId:a,tab:s,index:o}],tabId:s.id}}function $Y(e,t,n,r){let i=CJ(e,t);if(gJ(e,n).host!==`dock`)return HY;if(i.id===n){let e=i.tabs.indexOf(t),n=r>e?r-1:r;return n===e?HY:[{type:`reorderTab`,tabId:t,index:n}]}return[KY(i,t,n,r)]}function eX(e,t,n,r,i,a){let o=CJ(e,n),s=gJ(e,r);if(s.host!==`dock`)return HY;let c=DY(i);if(c===void 0)return o.id===r?HY:[KY(o,n,r,s.tabs.length)];let l=o.id===r&&o.tabs.length===1;if(l&&a===void 0||!TY(e))return HY;let u=t(`pane`),d=[{type:`split`,paneId:r,axis:c.axis,direction:c.direction,newPaneId:u,newSplitId:t(`split`)}];return l&&a!==void 0&&d.push({type:`openTab`,paneId:r,tab:a(t(`tab`)),index:o.tabs.length}),d.push(KY(o,n,u,0)),d}function tX(e,t,n,r){let i=e.floats.length*BY,a=t(`float`);return{ops:[{type:`float`,tabId:n,newPaneId:a,rect:r??{x:VY.x+i,y:VY.y+i,width:xY.width,height:xY.height}}],paneId:a}}function nX(e,t,n){let r=n??GY(e);return[{type:`unfloat`,paneId:t,toPaneId:r,index:gJ(e,r).tabs.length}]}function rX(e,t,n){return[{type:`resize`,splitId:e,sizes:OY(t,n)}]}function iX(e,t,n){let r=[],i=e;for(;;){let e=wJ(i).find(e=>e!==i.rootId&&gJ(i,e).tabs.length===0);if(e===void 0)break;let t={type:`merge`,paneId:e};r.push(t),i=sY(i,t).state}let a=hJ(i,i.rootId);return a.kind===`pane`&&a.tabs.length===0&&n!==void 0&&r.push({type:`openTab`,paneId:a.id,tab:n(t(`tab`)),index:0}),r}function aX(e=0){let t=e;return{next:(e=>(t+=1,`${e}${t}`))}}function oX(e,t,n=`push`){let r=e.next(`pane`),i=t?.(e.next(`tab`));return{nodes:{[r]:{kind:`pane`,id:r,host:`dock`,tabs:i===void 0?[]:[i.id],activeTabId:i?.id,rect:void 0}},tabs:i===void 0?{}:{[i.id]:i},rootId:r,floats:[],activePaneId:r,expanded:!1,mode:n}}var sX=class{minter;sequencer;listeners=new Set;makePaneTab;snapshot;constructor(e={}){this.minter=aX(),this.makePaneTab=e.makePaneTab,this.sequencer=new yY(oX(this.minter,e.makeInitialTab,e.mode)),this.snapshot=this.buildSnapshot()}subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});getSnapshot=()=>this.snapshot;get ops(){return this.sequencer.ops}buildSnapshot(){let e=this.sequencer.state;return{state:e,canUndo:this.sequencer.canUndo,canRedo:this.sequencer.canRedo,canSplit:TY(e),opCount:this.sequencer.ops.length,cursor:this.sequencer.cursor}}commit(){this.snapshot=this.buildSnapshot();for(let e of[...this.listeners])e()}get state(){return this.sequencer.state}get mint(){return this.minter.next}run(e,t=!1){if(e.length===0)return!1;if(t){let t=cY(this.state,e);e=[...e,...iX(t,this.mint,t.floats.length>0?this.makePaneTab:void 0)]}return this.sequencer.dispatchAll(e),this.commit(),!0}setExpanded(e){this.run(qY(this.state,e))}toggleExpanded(){this.setExpanded(!this.state.expanded)}setMode(e){this.run(JY(this.state,e))}splitPane(e){return this.run(YY(this.state,this.mint,e,this.makePaneTab))}addTab(e){return this.run(XY(this.state,this.mint,e,this.makePaneTab))}openContent(e){let t=ZY(this.state,this.mint,e);return this.run(t.ops),t.tabId}duplicateTab(e){let t=QY(this.state,this.mint,e);return this.run(t.ops),t.tabId}closeTab(e){this.run([{type:`closeTab`,tabId:e}],!0)}focusTab(e){this.run([{type:`focusTab`,tabId:e}])}focusPane(e){this.run([{type:`focusPane`,paneId:e}])}reorderTab(e,t){this.run([{type:`reorderTab`,tabId:e,index:t}])}placeTab(e,t,n){return this.run($Y(this.state,e,t,n),!0)}dropTab(e,t,n){return this.run(eX(this.state,this.mint,e,t,n),!0)}floatTab(e,t){let n=tX(this.state,this.mint,e,t);return this.run(n.ops,!0),n.paneId}unfloatPane(e,t){this.run(nX(this.state,e,t))}moveFloat(e,t,n){this.run([{type:`moveFloat`,paneId:e,x:t,y:n}])}resizeFloat(e,t){this.run([{type:`resizeFloat`,paneId:e,rect:t}])}resizeSplit(e,t){this.run(rX(e,t))}undo(){return this.sequencer.undo()?(this.commit(),!0):!1}redo(){return this.sequencer.redo()?(this.commit(),!0):!1}activeDockPaneId(){return GY(this.state)}},cX={x:0,y:0,width:0,height:0},lX={row:!0,column:!0};function uX(e){return e===null?cX:e.getBoundingClientRect()}function dX(e){let t=Number.parseFloat(e);return Number.isFinite(t)?t:0}function fX(e){let t=[];for(let n of e.querySelectorAll(`[data-dockkit-pane]`)){let e=n.dataset.dockkitPane;e!==void 0&&t.push([e,n])}return t}function pX(e){let t=e.querySelector(`[data-dockkit-tab]`);if(t===null)return MY.chip;let n=getComputedStyle(t),r=dX(n.minWidth);return r<=0?MY.chip:n.boxSizing===`border-box`?r:r+dX(n.paddingLeft)+dX(n.paddingRight)+dX(n.borderLeftWidth)+dX(n.borderRightWidth)}function mX(e){let t=e.querySelector(`[data-dockkit-divider]`);if(t===null)return MY.divider;let{width:n,height:r}=t.getBoundingClientRect(),i=Math.min(n,r);return i>0?i:MY.divider}function hX(e){let t=e.querySelector(`[data-dockkit-split-button]`);if(t===null)return 0;let n=t.getBoundingClientRect().width;if(!(n>0))return 0;let r=e.querySelector(`[data-dockkit-strip]`);return n+(r===null?0:dX(getComputedStyle(r).columnGap))}function gX(e,t=!1){let n={divider:mX(e),chip:pX(e),body:MY.body},r=new Map;for(let[i,a]of fX(e))r.set(i,NY({pane:uX(a),strip:uX(a.querySelector(`[data-dockkit-strip]`)),chipsWidth:uX(a.querySelector(`[data-dockkit-strip-tabs]`)).width,fillWidth:uX(a.querySelector(`[data-dockkit-strip-fill]`)).width,splitControlWidth:t?hX(a):0},n));return r}function _X(e,t){return e.get(t)??lX}function vX(e,t){if(e.size!==t.size)return!1;for(let[n,r]of e){let e=t.get(n);if(e===void 0||e.row!==r.row||e.column!==r.column)return!1}return!0}function yX(e,t){typeof e.setPointerCapture==`function`&&e.setPointerCapture(t)}function bX(e,t,n){yX(e,t);let r=new AbortController,{signal:i}=r;e.dataset.dockkitPointer=String(t),i.addEventListener(`abort`,()=>{e.dataset.dockkitPointer===String(t)&&delete e.dataset.dockkitPointer},{once:!0});let a=e=>e.pointerId===t;return window.addEventListener(`pointermove`,e=>{a(e)&&n.move(e)},{signal:i}),window.addEventListener(`pointerup`,e=>{a(e)&&(r.abort(),n.up(e))},{signal:i}),window.addEventListener(`pointercancel`,e=>{a(e)&&(r.abort(),n.cancel())},{signal:i}),()=>{r.abort()}}function xX(e){let t=(0,P.useRef)(void 0);return(0,P.useEffect)(()=>()=>{t.current?.stop()},[]),(n,r,i)=>{t.current?.end();let a=()=>{t.current=void 0,e()},o=bX(n,r,{move:i.move,up:e=>{a(),i.up(e)},cancel:a});t.current={stop:o,end:()=>{o(),a()}}}}var SX=new WeakMap,CX=new Set([`Tab`,`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`,`Home`,`End`]);function wX(e,t){SX.get(e)?.();let n=()=>{e.removeAttribute(`data-dsh-automatic-focus`),e.removeEventListener(`blur`,n),e.removeEventListener(`keydown`,r,!0),SX.delete(e)},r=e=>{e.isComposing||e.ctrlKey||e.altKey||e.metaKey||!CX.has(e.key)||n()};SX.set(e,n),e.setAttribute(`data-dsh-automatic-focus`,``),e.addEventListener(`blur`,n),e.addEventListener(`keydown`,r,!0),e.focus(t),e.matches(`:focus`)||n()}function TX(e){let t=!1,n=!1,r=()=>{t=!0},i=()=>{t=!1,n=!0},a=()=>{n=!1},o=()=>{t=!1,n=!1};return e.addEventListener(`compositionstart`,r,!0),e.addEventListener(`compositionend`,i,!0),e.addEventListener(`keyup`,a,!0),e.defaultView?.addEventListener(`blur`,o),{guards:e=>{let r=t||n||e.isComposing||e.keyCode===229;return n=!1,r},dispose:()=>{e.removeEventListener(`compositionstart`,r,!0),e.removeEventListener(`compositionend`,i,!0),e.removeEventListener(`keyup`,a,!0),e.defaultView?.removeEventListener(`blur`,o)}}}var EX=new WeakMap,DX=`button:not(:disabled), input:not(:disabled), textarea:not(:disabled), select:not(:disabled), a[href], [tabindex="0"]`;function OX(e,t,n){let r=(0,P.useRef)(n);r.current=n,(0,P.useLayoutEffect)(()=>{let n=e.current;if(!t||n===null)return;let i=n.ownerDocument,a=TX(i),o=i.activeElement,s=EX.get(i)??[];EX.set(i,s);let c={element:n,close:()=>{r.current()}};s.push(c);let l=n.querySelector(`[data-modal-autofocus]`)??n.querySelector(DX)??n;n.contains(i.activeElement)||wX(l);let u=e=>{let t=a.guards(e);if(s.at(-1)!==c||e.defaultPrevented||t||e.ctrlKey||e.altKey||e.metaKey||(e.key===`Escape`&&!e.shiftKey&&(e.preventDefault(),e.repeat||r.current()),e.key!==`Tab`)||i.activeElement?.closest(`[role="menu"]`))return;let o=[...n.querySelectorAll(DX)].filter(e=>!e.closest(`[inert], [hidden]`)),l=o[0]??n,u=o.at(-1)??n,d=e.shiftKey?i.activeElement===l:i.activeElement===u;(i.activeElement===n||!n.contains(i.activeElement)||d)&&(e.preventDefault(),(e.shiftKey?u:l).focus())};return i.addEventListener(`keydown`,u),()=>{a.dispose();let e=s.at(-1)===c;if(s.splice(s.indexOf(c),1),i.removeEventListener(`keydown`,u),s.length===0&&EX.delete(i),e){let e=o instanceof HTMLElement&&o.isConnected?o:s.at(-1)?.element;e!==void 0&&wX(e)}}},[e,t])}var kX={split:`_split_1s7ij_17`,splitRow:`_splitRow_1s7ij_24`,splitColumn:`_splitColumn_1s7ij_28`,splitCell:`_splitCell_1s7ij_32`,divider:`_divider_1s7ij_39`,surface:`_surface_1s7ij_125`,tabLayout:`_tabLayout_1s7ij_134`,tabCell:`_tabCell_1s7ij_142`,emptyTabHost:`_emptyTabHost_1s7ij_143`,floatingCell:`_floatingCell_1s7ij_156`,tabHost:`_tabHost_1s7ij_162`,float:`_float_1s7ij_156`,tabHostHeader:`_tabHostHeader_1s7ij_177`,tabHostBody:`_tabHostBody_1s7ij_181`,tabLayoutDivider:`_tabLayoutDivider_1s7ij_186`,pane:`_pane_1s7ij_209`,tabStrip:`_tabStrip_1s7ij_237`,stripTabs:`_stripTabs_1s7ij_257`,stripFill:`_stripFill_1s7ij_288`,stripChrome:`_stripChrome_1s7ij_296`,paneBody:`_paneBody_1s7ij_318`,slot:`_slot_1s7ij_327`,tabActive:`_tabActive_1s7ij_346`,slotCaret:`_slotCaret_1s7ij_346`,tab:`_tab_1s7ij_134`,tabTitle:`_tabTitle_1s7ij_389`,floatTitle:`_floatTitle_1s7ij_409`,tabClose:`_tabClose_1s7ij_417`,addTab:`_addTab_1s7ij_449`,tabQuiet:`_tabQuiet_1s7ij_488`,tabDragging:`_tabDragging_1s7ij_505`,iconButton:`_iconButton_1s7ij_511`,menu:`_menu_1s7ij_547`,menuItem:`_menuItem_1s7ij_561`,empty:`_empty_1s7ij_143`,dockScrim:`_dockScrim_1s7ij_599`,dockScrimIn:`_dockScrimIn_1s7ij_1`,dockHint:`_dockHint_1s7ij_601`,dockHintCard:`_dockHintCard_1s7ij_606`,dockHintIn:`_dockHintIn_1s7ij_1`,dockHintLabel:`_dockHintLabel_1s7ij_694`,floatHeader:`_floatHeader_1s7ij_765`,dockGlyph:`_dockGlyph_1s7ij_782`,floatBody:`_floatBody_1s7ij_787`,floatResize:`_floatResize_1s7ij_797`},AX=4;function jX(e,t){let n=e.getBoundingClientRect(),r=t.offsetWidth,i=n.left+r+AX>window.innerWidth?Math.max(AX,n.right-r):n.left;return{top:n.bottom+AX,left:i}}function MX({labels:e,anchor:t,onClose:n,onDismiss:r,extras:i}){let a=(0,P.useRef)(null),[o,s]=(0,P.useState)(void 0),c=n!==void 0||P.Children.toArray(i).some(e=>e!==``);return(0,P.useLayoutEffect)(()=>{a.current!==null&&s(jX(t,a.current))},[t,c]),(0,P.useEffect)(()=>{let e=a.current;if(e===null)return;let n=e.ownerDocument,i=TX(n),o=a=>{if(i.guards(a)||a.defaultPrevented||a.key!==`Escape`||a.ctrlKey||a.altKey||a.metaKey||a.shiftKey||[...n.querySelectorAll(`[role="dialog"][aria-modal="true"], [role="menu"]`)].at(-1)!==e||(a.preventDefault(),a.repeat))return;let o=e.contains(n.activeElement);r(),o&&wX(t)};n.addEventListener(`keydown`,o,!0);let s=t=>{t.target instanceof Node&&e.contains(t.target)||r()};return window.addEventListener(`pointerdown`,s,!0),()=>{i.dispose(),n.removeEventListener(`keydown`,o,!0),window.removeEventListener(`pointerdown`,s,!0)}},[t,r,c]),c?(0,jt.createPortal)((0,F.jsxs)(kp,{className:kX.menu,ref:a,role:`menu`,"data-dockkit-tab-menu":!0,style:o??{visibility:`hidden`,top:0,left:0},onPointerDown:e=>{e.stopPropagation()},onClick:e=>{e.stopPropagation()},children:[n!==void 0&&(0,F.jsx)(`button`,{type:`button`,role:`menuitem`,className:kX.menuItem,"data-dockkit-menu-close":!0,onClick:n,children:e.closeTab}),i]}),document.body):null}function NX(e){e.scrollWidth>e.clientWidth+1?e.dataset.dockkitTabClipped=``:delete e.dataset.dockkitTabClipped}function PX({children:e}){let t=(0,P.useRef)(null);return(0,P.useLayoutEffect)(()=>{t.current!==null&&NX(t.current)}),(0,P.useLayoutEffect)(()=>{let e=t.current;if(e===null||typeof ResizeObserver>`u`)return;let n=new ResizeObserver(()=>{NX(e)});return n.observe(e),()=>{n.disconnect()}},[]),(0,F.jsx)(`span`,{ref:t,className:kX.tabTitle,"data-dockkit-tab-title":!0,children:e})}var FX=`M9.67272 0.522841C10.8339 0.522841 11.76 0.522714 12.4963 0.602493C13.2453 0.683657 13.8789 0.854248 14.4264 1.25197C14.7504 1.48739 15.0355 1.77247 15.2709 2.0965C15.6686 2.64394 15.8392 3.27758 15.9204 4.02655C16.0002 4.7629 16 5.68895 16 6.85014V9.14986C16 10.3111 16.0002 11.2371 15.9204 11.9735C15.8392 12.7224 15.6686 13.3561 15.2709 13.9035C15.0355 14.2275 14.7504 14.5126 14.4264 14.748C13.8789 15.1458 13.2453 15.3163 12.4963 15.3975C11.76 15.4773 10.8339 15.4772 9.67272 15.4772H6.3273C5.16611 15.4772 4.24006 15.4773 3.50371 15.3975C2.75474 15.3163 2.1211 15.1458 1.57366 14.748C1.24963 14.5126 0.964549 14.2275 0.729131 13.9035C0.331407 13.3561 0.160817 12.7224 0.0796529 11.9735C-0.000126137 11.2371 1.25338e-09 10.3111 1.25338e-09 9.14986V6.85014C1.25329e-09 5.68895 -0.000126137 4.7629 0.0796529 4.02655C0.160817 3.27758 0.331407 2.64394 0.729131 2.0965C0.964549 1.77247 1.24963 1.48739 1.57366 1.25197C2.1211 0.854248 2.75474 0.683657 3.50371 0.602493C4.24006 0.522714 5.16611 0.522841 6.3273 0.522841H9.67272ZM4.1828 14.0873L5.54303 14.1118C5.78636 14.1128 6.04709 14.1169 6.3273 14.1169H9.67272C10.8639 14.1169 11.7032 14.1164 12.3493 14.0465C12.9824 13.9779 13.3497 13.8494 13.6268 13.6482C13.8354 13.4966 14.0195 13.3125 14.1711 13.1039C14.3723 12.8268 14.5007 12.4595 14.5693 11.8264C14.6393 11.1803 14.6398 10.341 14.6398 9.14986V6.85014C14.6398 5.65896 14.6393 4.81967 14.5693 4.1736C14.5007 3.54048 14.3723 3.17318 14.1711 2.89609C14.0195 2.68747 13.8354 2.50337 13.6268 2.35179C13.3497 2.1506 12.9824 2.02212 12.3493 1.95353C11.7032 1.88358 10.8639 1.88307 9.67272 1.88307H6.3273C6.04709 1.88307 5.78636 1.8862 5.54303 1.88715L4.1828 1.91166C3.99125 1.9216 3.8148 1.93577 3.65076 1.95353C3.01764 2.02212 2.65034 2.1506 2.37325 2.35179C2.16463 2.50337 1.98052 2.68747 1.82895 2.89609C1.62776 3.17318 1.49928 3.54048 1.43069 4.1736C1.36074 4.81967 1.36023 5.65896 1.36023 6.85014V9.14986C1.36023 10.341 1.36074 11.1803 1.43069 11.8264C1.49928 12.4595 1.62776 12.8268 1.82895 13.1039C1.98052 13.3125 2.16463 13.4966 2.37325 13.6482C2.65034 13.8494 3.01764 13.9779 3.65076 14.0465C3.81478 14.0642 3.99127 14.0774 4.1828 14.0873Z`;function IX(){return(0,F.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,children:[(0,F.jsx)(`path`,{d:`M13.5 1.5H2.5C1.94772 1.5 1.5 1.94772 1.5 2.5V13.5C1.5 14.0523 1.94772 14.5 2.5 14.5H13.5C14.0523 14.5 14.5 14.0523 14.5 13.5V2.5C14.5 1.94772 14.0523 1.5 13.5 1.5Z`,stroke:`currentColor`}),(0,F.jsx)(`path`,{d:`M8 1.5V14.5`,stroke:`currentColor`})]})}var LX={center:`M4.56 3.48H11.44A1.6 1.6 0 0 1 13.04 5.08V10.92A1.6 1.6 0 0 1 11.44 12.52H4.56A1.6 1.6 0 0 1 2.96 10.92V5.08A1.6 1.6 0 0 1 4.56 3.48Z`,left:`M4 0.523H8V15.477H4A4 4 0 0 1 0 11.477V4.523A4 4 0 0 1 4 0.523Z`,right:`M8 0.523H12A4 4 0 0 1 16 4.523V11.477A4 4 0 0 1 12 15.477H8Z`,top:`M0 8V4.523A4 4 0 0 1 4 0.523H12A4 4 0 0 1 16 4.523V8Z`,bottom:`M0 8H16V11.477A4 4 0 0 1 12 15.477H4A4 4 0 0 1 0 11.477Z`};function RX({zone:e}){return(0,F.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,children:[(0,F.jsx)(`path`,{fillRule:`evenodd`,clipRule:`evenodd`,d:FX,fill:`currentColor`}),(0,F.jsx)(`path`,{d:LX[e],fill:`currentColor`})]})}function zX({zone:e,active:t,labels:n}){return(0,F.jsx)(`div`,{className:kX.dockHint,"data-dockkit-dock-zone":e,"data-dockkit-drop-active":t||void 0,children:(0,F.jsxs)(`div`,{className:kX.dockHintCard,children:[(0,F.jsx)(RX,{zone:e}),(0,F.jsx)(`span`,{className:kX.dockHintLabel,children:n.dropZone[e]})]})})}function BX(e,t,n){let r=t.length,i=t.indexOf(n);switch(e){case`ArrowLeft`:return t[(i-1+r)%r];case`ArrowRight`:return t[(i+1)%r];case`Home`:return t[0];case`End`:return t.at(-1);default:return}}function VX(e){return e===`Enter`||e===` `}function HX(e){let t=e.scrollLeft>1,n=e.scrollLeft+e.clientWidth<e.scrollWidth-1;if(t&&n)return`start end`;if(t)return`start`;if(n)return`end`}function UX(e,t){(0,P.useLayoutEffect)(()=>{let t=e.current;if(t===null)return;let n=()=>{let e=HX(t);e===void 0?delete t.dataset.dockkitStripScroll:t.dataset.dockkitStripScroll=e};n(),t.addEventListener(`scroll`,n,{passive:!0});let r=typeof ResizeObserver>`u`?void 0:new ResizeObserver(n);return r?.observe(t),()=>{t.removeEventListener(`scroll`,n),r?.disconnect()}},[e,t])}function WX(e,t,n,r){(0,P.useLayoutEffect)(()=>{let n=e.current,i=r===void 0?void 0:t.get(r);if(n===null||i===void 0)return;let a=n.getBoundingClientRect(),o=i.getBoundingClientRect();o.left<a.left?n.scrollLeft+=o.left-a.left-GX:o.right>a.right&&(n.scrollLeft+=o.right-a.right+GX)},[e,t,n,r])}var GX=24;function KX(e,t){switch(t){case`budget`:return e.splitPaneDisabled;case`width`:return e.splitPaneNarrow}}function qX({state:e,pane:t,callbacks:r}){let[i,a]=(0,P.useState)(void 0),[o]=(0,P.useState)(()=>new Map),s=(0,P.useRef)(null);UX(s,t.tabs),WX(s,o,t.tabs,t.activeTabId);let c=r.splitBlock(t.id),l=r.dropTarget,u=l!==void 0&&l.kind===`strip`&&l.paneId===t.id?l.index:void 0,d=n=>{(e.activePaneId!==t.id||t.activeTabId!==n)&&r.onFocusTab(n)},f=e=>{let t=o.get(e);t!==void 0&&t.focus()};return(0,F.jsxs)(`div`,{className:kX.tabStrip,role:`tablist`,"data-dockkit-strip":t.id,"data-window-drag":e.floats.length===0||void 0,children:[(0,F.jsxs)(`div`,{ref:s,className:kX.stripTabs,role:`presentation`,"data-dockkit-strip-tabs":t.id,children:[t.tabs.map((s,c)=>{let l=vJ(e,s),p=s===t.activeTabId,m=r.canCloseTab(s),h=!m&&t.tabs.length===1;return(0,F.jsxs)(P.Fragment,{children:[(c>0||u===c)&&(0,F.jsx)(`div`,{className:n(kX.slot,u===c&&kX.slotCaret),"data-dockkit-caret":u===c?c:void 0}),(0,F.jsxs)(`div`,{role:`tab`,"aria-selected":p,tabIndex:p?0:-1,className:n(kX.tab,p&&kX.tabActive,h&&kX.tabQuiet,r.draggingTabId===s&&kX.tabDragging),"data-dockkit-tab":s,"data-dockkit-tab-quiet":h||void 0,ref:e=>{e===null?o.delete(s):o.set(s,e)},onPointerDown:e=>{e.button!==2&&r.onTabPressed(s,e)},onClick:e=>{e.stopPropagation(),d(s)},onKeyDown:e=>{if(e.target!==e.currentTarget||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey||e.nativeEvent.isComposing)return;let n=BX(e.key,t.tabs,s);n===void 0?VX(e.key)&&(e.preventDefault(),d(s)):(e.preventDefault(),f(n))},onContextMenu:e=>{e.preventDefault();let t=e.currentTarget;a(e=>e?.tabId===s?void 0:{tabId:s,anchor:t})},children:[(0,F.jsx)(PX,{children:r.renderTabTitle?.(l)??l.title}),m&&(0,F.jsx)(hO,{disabled:i!==void 0,label:r.labels.closeTab,shortcutKeys:r.labels.closeTabKeys,side:`bottom`,delayMs:500,children:(0,F.jsx)(`button`,{type:`button`,className:kX.tabClose,"aria-label":r.labels.closeTab,"aria-keyshortcuts":r.labels.closeTabShortcut,"data-dockkit-tab-close":s,onPointerDown:e=>{e.stopPropagation()},onClick:e=>{e.stopPropagation(),r.onCloseTab(s)},children:(0,F.jsx)(le,{size:14})})}),i?.tabId===s&&(0,F.jsx)(MX,{labels:r.labels,anchor:i.anchor,onClose:m?()=>{a(void 0),r.onCloseTab(s)}:void 0,onDismiss:()=>{a(void 0)},extras:r.renderTabMenuItems?.(l,()=>{a(void 0)})})]})]},s)}),u===t.tabs.length&&(0,F.jsx)(`div`,{className:n(kX.slot,kX.slotCaret),"data-dockkit-caret":u})]}),r.canAddTab(t.id)&&(0,F.jsx)(hO,{label:r.labels.addTab,side:`bottom`,delayMs:500,children:(0,F.jsx)(`button`,{type:`button`,className:kX.addTab,"aria-label":r.labels.addTab,"data-dockkit-add-tab":t.id,onClick:e=>{e.stopPropagation(),r.onAddTab(t.id)},children:(0,F.jsx)(me,{size:14})})}),(0,F.jsx)(`div`,{className:kX.stripFill,"data-dockkit-strip-fill":!0}),!(r.hideSplitWhenBlocked&&c!==void 0)&&(0,F.jsx)(hO,{label:c===void 0?r.labels.splitPane:KX(r.labels,c),shortcutKeys:r.labels.splitPaneKeys,side:`bottom`,delayMs:500,children:(0,F.jsx)(`span`,{tabIndex:c===void 0?void 0:0,"aria-label":c===void 0?void 0:KX(r.labels,c),children:(0,F.jsx)(`button`,{type:`button`,className:kX.iconButton,"aria-label":r.labels.splitPane,"aria-keyshortcuts":r.labels.splitPaneShortcut,disabled:c!==void 0,"data-dockkit-split-button":t.id,"data-dockkit-split-blocked":c,onClick:e=>{e.stopPropagation(),r.onSplitPane(t.id)},children:(0,F.jsx)(IX,{})})})}),t.id===r.chromePaneId&&r.chrome!==void 0&&(0,F.jsx)(`div`,{className:kX.stripChrome,"data-dockkit-strip-chrome":!0,onClick:e=>{e.stopPropagation()},children:r.chrome})]})}function JX({pane:e,callbacks:t}){let n=t.dropTarget,r=n?.kind===`zone`&&n.paneId===e.id?n.zone:void 0;return r===void 0?null:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`div`,{className:kX.dockScrim,"data-dockkit-dock-scrim":!0}),t.horizontalDrops&&r!==`center`?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(zX,{zone:`left`,active:r===`left`,labels:t.labels}),(0,F.jsx)(zX,{zone:`right`,active:r===`right`,labels:t.labels})]}):(0,F.jsx)(zX,{zone:r,active:!0,labels:t.labels})]})}function YX({state:e,pane:t,callbacks:n}){let r=t.activeTabId===void 0?void 0:vJ(e,t.activeTabId);return(0,F.jsxs)(`section`,{className:kX.pane,"data-dockkit-pane":t.id,tabIndex:-1,"data-dockkit-pane-active":e.activePaneId===t.id||void 0,onClick:()=>{e.activePaneId!==t.id&&n.onFocusPane(t.id)},children:[(0,F.jsx)(qX,{state:e,pane:t,callbacks:n}),(0,F.jsxs)(`div`,{className:kX.paneBody,children:[r===void 0?(0,F.jsx)(`p`,{className:kX.empty,children:n.labels.emptyPane}):n.renderTab(r),(0,F.jsx)(JX,{pane:t,callbacks:n})]})]})}function XX(e,t,n){let r=t-e.originX,i=n-e.originY;return e.mode===`move`?IY(e.rect,r,i):LY(e.rect,r,i,SY)}function ZX(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function QX(e,t){return e.activePaneId===t&&e.floats.at(-1)===t}function $X(e,t){let[n,r]=(0,P.useState)(void 0),i=xX(()=>{r(void 0)}),a=n=>{QX(e,n)||t.focusPane(n)};return{preview:n,raise:a,drag:(n,o,s)=>{s.stopPropagation();let c={mode:n,originX:s.clientX,originY:s.clientY,rect:yJ(gJ(e,o))};i(s.currentTarget,s.pointerId,{move:e=>{r({paneId:o,rect:XX(c,e.clientX,e.clientY)})},up:e=>{let r=XX(c,e.clientX,e.clientY);ZX(r,c.rect)?a(o):n===`move`?t.moveFloat(o,r.x,r.y):t.resizeFloat(o,r)}})}}}function eZ({paneId:e,tab:t,labels:r,intents:i,renderTabTitle:a,canCloseTab:o,drag:s}){return(0,F.jsxs)(`header`,{className:n(kX.tabStrip,kX.floatHeader),"data-dockkit-float-grip":e,onPointerDown:t=>{s(`move`,e,t)},children:[(0,F.jsx)(`div`,{className:n(kX.tab,kX.floatTitle),"data-dockkit-float-title":!0,children:(0,F.jsx)(PX,{children:a?.(t)??t.title})}),(0,F.jsx)(`div`,{className:kX.stripFill}),(0,F.jsx)(hO,{label:r.dockFloat,side:`bottom`,delayMs:500,children:(0,F.jsx)(`button`,{type:`button`,className:kX.iconButton,"aria-label":r.dockFloat,"data-dockkit-float-dock":e,onPointerDown:e=>{e.stopPropagation()},onClick:()=>{i.unfloatPane(e)},children:(0,F.jsx)(te,{className:kX.dockGlyph})})}),(o?.(t.id)??!0)&&(0,F.jsx)(hO,{label:r.closeTab,shortcutKeys:r.closeTabKeys,side:`bottom`,delayMs:500,children:(0,F.jsx)(`button`,{type:`button`,className:kX.iconButton,"aria-label":r.closeTab,"data-dockkit-float-close":e,onPointerDown:e=>{e.stopPropagation()},onClick:()=>{i.closeTab(t.id)},children:(0,F.jsx)(O,{})})})]})}function tZ({state:e,callbacks:t,intents:r,tab:i,pane:a,column:o,floats:s,focusRequest:c,keepMounted:l,active:u=!0}){let d=a.host===`float`,f=d||a.activeTabId===i.id,p=u&&f&&(d||e.expanded),m=l?.(i)??!1,[h,g]=(0,P.useState)(p);p&&!h&&g(!0);let _=(0,P.useRef)(null),v=(0,P.useRef)(null);(0,P.useLayoutEffect)(()=>{let e=_.current;e.inert=!p;let t=document.activeElement;!p&&t instanceof HTMLElement&&e.contains(t)&&t.blur();let n=c.current;p&&n?.tabId===i.id&&(c.current=void 0,(t===null||t===document.body||t===document.documentElement||t===n.origin)&&[...e.querySelector(`[data-dockkit-strip]`)?.querySelectorAll(`[data-dockkit-tab]`)??[]].find(e=>e.dataset.dockkitTab===i.id)?.focus({preventScroll:!0}))},[p,i.id,c]),(0,P.useEffect)(()=>{let n=v.current,r=()=>{p&&(d?s.raise(a.id):e.activePaneId!==a.id&&t.onFocusPane(a.id))};return n.addEventListener(`focus`,r,!0),()=>{n.removeEventListener(`focus`,r,!0)}},[p,d,s,a.id,e.activePaneId,t]);let y=d&&s.preview?.paneId===a.id?s.preview.rect:void 0,b=d?y??yJ(a):void 0,x=y===void 0?e.floats.indexOf(a.id)+1:e.floats.length+1;return(0,F.jsx)(`div`,{className:n(kX.tabCell,d&&kX.floatingCell),hidden:!f,"data-dockkit-host":d?`float`:`dock`,"data-dockkit-column":d?void 0:o,style:{gridColumn:d?1:o*2+1,gridRow:1,order:d?x:0},children:(0,F.jsxs)(`section`,{ref:_,tabIndex:-1,className:n(kX.tabHost,d?kX.float:kX.pane),"aria-hidden":!p||void 0,"data-dockkit-content":i.id,"data-dockkit-pane":!d&&f?a.id:void 0,"data-dockkit-pane-active":!d&&e.activePaneId===a.id||void 0,"data-dockkit-float":d?a.id:void 0,"data-dockkit-float-active":d&&e.activePaneId===a.id||void 0,"data-dockkit-column":d?void 0:o,style:b===void 0?void 0:{left:b.x,top:b.y,width:b.width,height:b.height},onPointerDown:()=>{d&&s.raise(a.id)},onClick:()=>{!d&&e.activePaneId!==a.id&&t.onFocusPane(a.id)},children:[(0,F.jsx)(`div`,{className:kX.tabHostHeader,children:f&&(d?(0,F.jsx)(eZ,{paneId:a.id,tab:i,labels:t.labels,intents:r,renderTabTitle:t.renderTabTitle,canCloseTab:t.canCloseTab,drag:s.drag}):(0,F.jsx)(qX,{state:e,pane:a,callbacks:t}))}),(0,F.jsxs)(`div`,{ref:v,className:n(kX.tabHostBody,d?kX.floatBody:kX.paneBody),children:[h&&(m||u&&f)?t.renderTab(i):null,!d&&(0,F.jsx)(JX,{pane:a,callbacks:t})]}),d&&(0,F.jsx)(`div`,{className:kX.floatResize,"data-dockkit-float-resize":a.id,onPointerDown:e=>{s.drag(`resize`,a.id,e)}})]})})}function nZ(e){let{state:t,callbacks:r,preview:i}=e,a=(0,P.useRef)(void 0),o={...r,onFocusTab:e=>{a.current=CJ(t,e).activeTabId===e?void 0:{tabId:e,origin:document.activeElement},r.onFocusTab(e)}},s=hJ(t,t.rootId);if(s.kind===`split`&&(s.axis!==`row`||s.children.length!==2))throw Error(`DockLayout requires one pane or two horizontally split panes`);let c=s.kind===`pane`?[s]:s.children.map(e=>gJ(t,e)),l=s.kind===`split`?i?.splitId===s.id?i.sizes:s.sizes:[1],u=$X(t,e.intents),d=l.map(e=>`minmax(0, ${e}fr)`).join(` 0px `);return(0,F.jsxs)(`div`,{className:kX.tabLayout,"data-dockkit-split":s.kind===`split`?s.id:void 0,style:{gridTemplateColumns:d},children:[Object.values(t.tabs).sort((e,t)=>e.id.localeCompare(t.id)).map(n=>{let r=CJ(t,n.id);return(0,F.jsx)(tZ,{...e,callbacks:o,tab:n,pane:r,column:c.findIndex(e=>e.id===r.id),floats:u,focusRequest:a},n.id)}),c.filter(e=>e.tabs.length===0).map(e=>(0,F.jsx)(`div`,{className:kX.emptyTabHost,"data-dockkit-empty":!0,style:{gridColumn:c.indexOf(e)*2+1,gridRow:1},children:(0,F.jsx)(YX,{state:t,pane:e,callbacks:r})},e.id)),s.kind===`split`&&(0,F.jsx)(`div`,{className:n(kX.divider,kX.tabLayoutDivider),"data-dockkit-divider":`${s.id}:0`,style:{gridColumn:2,gridRow:1},onPointerDown:e=>{r.onDividerPressed(s.id,0,e)}})]})}var rZ={draggingTabId:void 0,dropTarget:void 0,sizes:void 0},iZ=new Map,aZ=()=>!0;function oZ(e,t,n,r,i,a){for(let[o,s]of fX(e)){let e=s.getBoundingClientRect();if(!kY(e,t,n))continue;let c=s.querySelector(`[data-dockkit-strip]`);if(c!==null&&kY(c.getBoundingClientRect(),t,n))return{kind:`strip`,paneId:o,index:jY([...c.querySelectorAll(`[data-dockkit-tab]`)].map(e=>e.getBoundingClientRect()),t)};let l=a===`horizontal`?r&&_X(i,o).row?t<e.x+e.width/2?`left`:`right`:`center`:AY(e,t,n);if(l!==`center`){let e=_X(i,o),t=l===`left`||l===`right`?e.row:e.column;if(!r||!t)return}return{kind:`zone`,paneId:o,zone:l}}}function sZ(e,t,n,r){let i=(e.axis===`row`?t:n)-e.origin,a=e.extent>0?i/e.extent:0;return OY(FY(e.sizes,e.index,a),r)}var cZ=1e-9;function lZ(e,t){return e.length===t.length&&e.every((e,n)=>{let r=t[n];return r!==void 0&&Math.abs(e-r)<cZ})}function uZ({state:e,canSplit:t,canAddTab:n,canCloseTab:r,intents:i,labels:a,renderTab:o,renderTabTitle:s,renderTabMenuItems:c,chrome:l,onRoom:u,draw:d,dropZones:f=`edges`,minPaneFraction:p=bY,hideSplitWhenBlocked:m=!1}){let h=(0,P.useRef)(null),[g,_]=(0,P.useState)(rZ),[v,y]=(0,P.useState)(iZ),b=xX(()=>{_(rZ)}),x=(0,P.useCallback)(e=>{let t=h.current;t!==null&&e(t)},[]),S=(0,P.useCallback)(()=>{x(e=>{let t=gX(e,m);y(e=>vX(e,t)?e:t)})},[x,m]);(0,P.useLayoutEffect)(()=>{S()}),(0,P.useEffect)(()=>{u?.(v)},[v,u]),(0,P.useEffect)(()=>{let e=h.current;if(e===null||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{S()});return t.observe(e),()=>{t.disconnect()}},[S]);let C={onFocusTab:i.focusTab.bind(i),onFocusPane:i.focusPane.bind(i),onSplitPane:i.splitPane.bind(i),onAddTab:i.addTab.bind(i),onCloseTab:i.closeTab.bind(i),onTabPressed:(e,n)=>{x(r=>{let a=n.clientX,o=n.clientY,s=!1;b(n.currentTarget,n.pointerId,{move:n=>{if(!s){if(!PY(a,o,n.clientX,n.clientY))return;s=!0}_({...rZ,draggingTabId:e,dropTarget:oZ(r,n.clientX,n.clientY,t,v,f)})},up:n=>{if(!s)return;let a=oZ(r,n.clientX,n.clientY,t,v,f);if(a===void 0){if(kY(r.getBoundingClientRect(),n.clientX,n.clientY))return;i.floatTab(e,RY(n.clientX,n.clientY,xY))}else a.kind===`strip`?i.placeTab(e,a.paneId,a.index):i.dropTab(e,a.paneId,a.zone)}})})},onDividerPressed:(t,n,r)=>{let a=r.currentTarget.parentElement;if(a===null)return;let o=_J(e,t),s=a.getBoundingClientRect(),c={splitId:t,index:n,axis:o.axis,origin:o.axis===`row`?r.clientX:r.clientY,extent:o.axis===`row`?s.width:s.height,sizes:o.sizes};b(r.currentTarget,r.pointerId,{move:e=>{_({...rZ,sizes:{splitId:t,sizes:sZ(c,e.clientX,e.clientY,p)}})},up:e=>{let n=sZ(c,e.clientX,e.clientY,p);lZ(n,c.sizes)||i.resizeSplit(t,n)}})},splitBlock:e=>t?_X(v,e).row?void 0:`width`:`budget`,hideSplitWhenBlocked:m,canAddTab:n??aZ,canCloseTab:r??aZ,dropTarget:g.dropTarget,horizontalDrops:f===`horizontal`,draggingTabId:g.draggingTabId,labels:a,renderTab:o,renderTabTitle:s,renderTabMenuItems:c,chromePaneId:LJ(e),chrome:l};return(0,F.jsx)(`div`,{className:kX.surface,ref:h,"data-dockkit-surface":!0,"data-dockkit-drop-zones":f,children:d(C,g.sizes)})}function dZ(e){return(0,F.jsx)(uZ,{...e,draw:(t,n)=>(0,F.jsx)(nZ,{...e,callbacks:t,preview:n})})}var fZ={session:`_session_nj5n1_24`,panel:`_panel_nj5n1_32`,iconButton:`_iconButton_nj5n1_121`,collapseGlyph:`_collapseGlyph_nj5n1_147`,panelBody:`_panelBody_nj5n1_151`,unavailable:`_unavailable_nj5n1_157`,tabTitle:`_tabTitle_nj5n1_165`,tabBody:`_tabBody_nj5n1_169`};function pZ(){return(0,F.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,children:(0,F.jsx)(`path`,{d:`M2.33203 10.4054V13.1681C2.33229 13.444 2.55605 13.6681 2.83203 13.6681H5.49512V14.6681H2.83203C2.00376 14.6681 1.33229 13.9963 1.33203 13.1681V10.4054H2.33203ZM14.6689 13.1681C14.6687 13.996 13.9968 14.6676 13.1689 14.6681H10.4951V13.6681H13.1689C13.4445 13.6676 13.6687 13.4437 13.6689 13.1681V10.4054H14.6689V13.1681ZM13.1689 1.33118C13.9969 1.33163 14.6688 2.00315 14.6689 2.83118V5.4054H13.6689V2.83118C13.6688 2.55544 13.4446 2.33162 13.1689 2.33118H10.4951V1.33118H13.1689ZM5.49512 2.33118H2.83203C2.55598 2.33118 2.33218 2.55516 2.33203 2.83118V5.4054H1.33203V2.83118C1.33218 2.00288 2.00369 1.33118 2.83203 1.33118H5.49512V2.33118Z`,fill:`currentColor`})})}function mZ(){return(0,F.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,children:[(0,F.jsx)(`path`,{d:`M9 2.5V6C9 6.26522 9.10536 6.51957 9.29289 6.70711C9.48043 6.89464 9.73478 7 10 7H13.5`,stroke:`currentColor`}),(0,F.jsx)(`path`,{d:`M7 13.5V10C7 9.73478 6.89464 9.48043 6.70711 9.29289C6.51957 9.10536 6.26522 9 6 9H2.5`,stroke:`currentColor`})]})}function hZ({sessionId:e,fullscreen:t,focus:n=!1,actions:r,t:i,shortcuts:a,toggleFullscreen:o}){let s=t?`push`:`fullscreen`,c=i(n?`chrome.exitFocus`:t?`chrome.exitFullscreen`:`chrome.toFullscreen`),l=a.find(e=>e.id===`pane.fullscreen.toggle`),u=a.find(e=>e.id===`sidebar.right.toggle`);return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(hO,{label:c,shortcutKeys:l?.keys,side:`bottom`,delayMs:500,children:(0,F.jsx)(`button`,{type:`button`,className:fZ.iconButton,"aria-label":c,"aria-keyshortcuts":l?.aria,"data-sidebar-right-mode":s,onClick:o,children:t?(0,F.jsx)(mZ,{}):(0,F.jsx)(pZ,{})})}),(0,F.jsx)(hO,{label:i(`chrome.collapse`),shortcutKeys:u?.keys,side:`bottom`,delayMs:500,children:(0,F.jsx)(`button`,{type:`button`,className:fZ.iconButton,"aria-label":i(`chrome.collapseAria`),"aria-keyshortcuts":u?.aria,"data-sidebar-right-toggle":!0,onClick:()=>{r.toggleExpanded(e)},children:(0,F.jsx)(te,{className:fZ.collapseGlyph})})})]})}function gZ(e,t,n){return{emptyPane:e(`dock.emptyPane`),splitPane:e(`dock.splitPane`),splitPaneShortcut:t?.aria,splitPaneKeys:t?.keys,splitPaneDisabled:e(`dock.splitPaneDisabled`),splitPaneNarrow:e(`dock.splitPaneNarrow`),closeTab:e(`dock.closeTab`),closeTabShortcut:n?.aria,closeTabKeys:n?.keys,addTab:e(`dock.addTab`),dockFloat:e(`dock.dockFloat`),closeFloat:e(`dock.closeFloat`),dropZone:{center:e(`dock.drop.center`),left:e(`dock.drop.left`),right:e(`dock.drop.right`),top:e(`dock.drop.top`),bottom:e(`dock.drop.bottom`)}}}var _Z={"command.close":`关闭当前页面/窗口`,"command.refresh":`刷新当前页面`,"command.noRefresh":`当前页面不支持刷新`,"command.toggle":`展开/收起右侧栏`,"command.fullscreen":`面板全屏/退出全屏`,"command.noSession":`请先选择会话`,"command.noFocus":`请先聚焦右侧面板`,"command.stale":`页面已切换,请重新聚焦`,"command.collapsed":`请先展开右侧栏`,"command.float":`浮动面板不支持此操作`,"command.empty":`请先打开页面`,"command.budget":`已达两格上限`,"command.width":`栏宽不足,拖宽侧边栏后再分栏`,"chrome.expand":`打开侧边栏`,"chrome.expandAria":`打开右侧边栏`,"chrome.collapse":`收起侧边栏`,"chrome.collapseAria":`收起右侧边栏`,"chrome.toFullscreen":`全屏`,"chrome.exitFullscreen":`退出全屏`,"chrome.exitFocus":`退出专注模式`,"dock.emptyPane":`空面板`,"dock.splitPane":`分栏`,"dock.splitPaneDisabled":`已达两格上限`,"dock.splitPaneNarrow":`栏宽不足,拖宽侧边栏后再分栏`,"dock.closeTab":`关闭`,"dock.addTab":`新标签页`,"dock.dockFloat":`收回到侧边栏`,"dock.closeFloat":`关闭`,"dock.drop.center":`移到这里`,"dock.drop.left":`左分栏`,"dock.drop.right":`右分栏`,"dock.drop.top":`上分栏`,"dock.drop.bottom":`下分栏`,"tab.guide.title":`开始`,"tab.unavailable":`这类内容还没有可用的查看方式。`},vZ={"command.close":`Close current page or window`,"command.refresh":`Refresh current page`,"command.noRefresh":`This page cannot be refreshed`,"command.toggle":`Toggle right sidebar`,"command.fullscreen":`Toggle panel fullscreen`,"command.noSession":`Select a session first`,"command.noFocus":`Focus a right sidebar pane first`,"command.stale":`The page changed; focus it again`,"command.collapsed":`Expand the right sidebar first`,"command.float":`This action is unavailable in a floating panel`,"command.empty":`Open a page first`,"command.budget":`Two panes is the limit`,"command.width":`Not enough width to split, widen the sidebar`,"chrome.expand":`Open sidebar`,"chrome.expandAria":`Open right sidebar`,"chrome.collapse":`Collapse sidebar`,"chrome.collapseAria":`Collapse right sidebar`,"chrome.toFullscreen":`Fullscreen`,"chrome.exitFullscreen":`Exit fullscreen`,"chrome.exitFocus":`Exit focus mode`,"dock.emptyPane":`Empty pane`,"dock.splitPane":`Split`,"dock.splitPaneDisabled":`Two panes is the limit`,"dock.splitPaneNarrow":`Not enough width to split, widen the sidebar`,"dock.closeTab":`Close`,"dock.addTab":`New tab`,"dock.dockFloat":`Send back to the sidebar`,"dock.closeFloat":`Close`,"dock.drop.center":`Move here`,"dock.drop.left":`Add left split`,"dock.drop.right":`Add right split`,"dock.drop.top":`Add top split`,"dock.drop.bottom":`Add bottom split`,"tab.guide.title":`Start`,"tab.unavailable":`Nothing here can view this kind of content yet.`},yZ={button:`_button_1rv3m_2`,md:`_md_1rv3m_23`,sm:`_sm_1rv3m_28`,primary:`_primary_1rv3m_36`,ghost:`_ghost_1rv3m_45`,outline:`_outline_1rv3m_54`,toolbar:`_toolbar_1rv3m_63`,icon:`_icon_1rv3m_71`},bZ=(0,P.forwardRef)(function({variant:e=`ghost`,size:t=`md`,icon:r,className:i,children:a,...o},s){return(0,F.jsxs)(`button`,{ref:s,type:`button`,className:n(yZ.button,yZ[e],yZ[t],i),...o,children:[r!=null&&(0,F.jsx)(`span`,{className:yZ.icon,children:r}),a]})}),xZ={button:`_button_11lrx_2`,icon:`_icon_11lrx_15`};function SZ(e,t){if(!e||typeof e!=`object`)throw Error(`Module must default export a plugin definition`);let n=e;if(n.id!==t||n.apiVersion!==1)throw Error(`Plugin id or apiVersion does not match the catalog`);if(typeof n.activate!=`function`)throw Error(`Plugin must declare synchronous activate(context)`);for(let e of[`slots`,`commands`,`menuItems`,`interactions`,`artifactTools`])if(n[e]!==void 0&&!Array.isArray(n[e]))throw Error(`${e} must be an array`);let r=new Set;for(let e of n.slots??[]){if(!e||![`composer.controls`,`turn.tail`,`rightbar.panel`,`rightbar.title`].includes(e.slot)||typeof e.id!=`string`||typeof e.component!=`function`||r.has(e.id))throw Error(`Invalid or duplicate slot`);r.add(e.id)}for(let e of[...n.commands??[],...n.menuItems??[]]){if(!e||typeof e.id!=`string`||typeof e.action!=`string`||r.has(e.id))throw Error(`Invalid or duplicate command/menu contribution`);r.add(e.id)}if((n.commands??[]).some(e=>!u(e)))throw Error(`Invalid command`);let i=new Set;for(let e of n.interactions??[]){if(!e||typeof e.kind!=`string`||!e.kind||i.has(e.kind)||typeof e.component!=`function`)throw Error(`Invalid or duplicate interaction`);i.add(e.kind)}if(n.composerPlaceholder!==void 0&&typeof n.composerPlaceholder!=`function`)throw Error(`Invalid composer placeholder`);if(n.composerAction!==void 0&&typeof n.composerAction!=`function`)throw Error(`Invalid composer action`);if(n.artifactTools?.some(e=>typeof e!=`string`))throw Error(`Invalid artifact tools`);if(n.workbench){let{entry:e,panels:t,toolViews:r,beforeSend:i}=n.workbench;if(i!==void 0&&typeof i!=`function`)throw Error(`Invalid workbench pre-send hook`);if(r!==void 0&&(!Array.isArray(r)||r.some(e=>!e||!Array.isArray(e.tools)||!e.tools.length||e.tools.some(e=>typeof e!=`string`||!e)||typeof e.component!=`function`)))throw Error(`Invalid workbench tool view`);if(n.workbench.resolvePanel!==void 0&&typeof n.workbench.resolvePanel!=`function`)throw Error(`Invalid workbench artifact resolver`);if(n.workbench.apiVersion!==1||!Array.isArray(t)||t.some(e=>typeof e.kind!=`string`||typeof e.component!=`function`)||new Set(t.map(e=>e.kind)).size!==t.length)throw Error(`Invalid workbench contribution`);if(e!==void 0&&(!e||typeof e.kind!=`string`||!e.kind||!p(e.label)||!p(e.description)||e.panelTitle!==void 0&&!p(e.panelTitle)||typeof e.icon!=`function`||!t.some(t=>t.kind===e.kind)))throw Error(`Invalid workbench entry`)}return n}function CZ(e,t,n){return new Promise((r,i)=>{let a,o=()=>s(Error(`Plugin load aborted`)),s=(e,n)=>{clearTimeout(a),t.removeEventListener(`abort`,o),e?i(e):r(n)};t.addEventListener(`abort`,o,{once:!0}),n!==void 0&&(a=setTimeout(()=>s(Error(`Plugin load timed out`)),n)),e.then(e=>s(null,e),e=>s(e)),t.aborted&&o()})}var wZ=class{controller=new AbortController;cleanups=[];disposed=!1;report;constructor(e){this.report=e}context(e){return{sessionId:e,signal:this.controller.signal,onDispose:e=>{if(typeof e!=`function`)throw Error(`onDispose expects a cleanup function`);this.disposed?this.clean(e):this.cleanups.push(e)}}}clean(e){try{e()}catch(e){this.report(e)}}dispose(){if(!this.disposed){this.disposed=!0,this.controller.abort();for(let e of this.cleanups.splice(0).reverse())this.clean(e)}}},TZ=(e,t=null)=>({sessionId:t,generation:e,plugins:[],errors:[],ready:!1}),EZ=class{environment;run=null;snapshot=TZ(0);generation=0;listeners=new Set;constructor(e){this.environment=e}getSnapshot=()=>this.snapshot;subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});update(e){this.snapshot=e;for(let e of this.listeners)e()}error(e,t,n,r){let i=`plugin=${t} session=${e.sessionId} generation=${e.generation} stage=${n}: ${r instanceof Error?r.message:String(r)}`;(this.environment.report??console.error)(i),this.run===e&&this.update({...this.snapshot,errors:[...this.snapshot.errors,i]})}async start(e,t){this.dispose();let n={sessionId:e,generation:++this.generation,controller:new AbortController,scopes:[]};this.run=n,this.update(TZ(n.generation,e));try{let r=await CZ(Promise.resolve().then(t),n.controller.signal);if(this.run!==n)return;for(let e of r.errors)this.error(n,`catalog`,`discover`,e);for(let t of r.plugins){if(this.run!==n)break;let r=new wZ(e=>this.error(n,t.id,`dispose`,e));n.scopes.push(r);let i=r.context(e),a=`load`;try{let e=await CZ(this.environment.loadModule(t.client),n.controller.signal,this.environment.loadTimeoutMs??1e4);if(this.run!==n)break;a=`validate`;let o=SZ(e?.default,t.id);if(t.style&&(a=`style`,await CZ(this.environment.loadStyle(t.style,i.signal).then(e=>{i.onDispose(e)}),n.controller.signal,this.environment.loadTimeoutMs??1e4)),this.run!==n)break;a=`activate`;let s=new Set(this.snapshot.plugins.flatMap(e=>e.definition.workbench?.panels.map(e=>e.kind)??[]));if(o.workbench?.panels.some(e=>s.has(e.kind)))throw Error(`Workbench panel kind already registered`);let c=o.activate(i);if(c!==void 0)throw Promise.resolve(c).catch(e=>this.error(n,t.id,`activate`,e)),Error(`activate must be synchronous and return void`);if(this.run!==n){r.dispose();break}this.update({...this.snapshot,plugins:[...this.snapshot.plugins,{id:t.id,definition:o,instanceId:`${n.generation}/${t.id}`}]})}catch(e){this.run===n&&this.error(n,t.id,a,e),r.dispose()}}}catch(e){this.run===n&&this.error(n,`catalog`,`discover`,e)}this.run===n&&this.update({...this.snapshot,ready:!0})}dispose(){let e=this.run;if(e){this.run=null,e.controller.abort();for(let t of e.scopes.reverse())t.dispose();this.update(TZ(this.generation))}}},DZ={"builtin:@pi-webapp/files":()=>N(()=>import(`./plugin-0Vwjcj6k.js`),__vite__mapDeps([34,2,3,35,36])),"builtin:@pi-webapp/terminal":()=>N(()=>import(`./plugin-q4wA1M0I.js`),__vite__mapDeps([37,2,3,38])),"builtin:@pi-webapp/git":()=>N(()=>import(`./plugin-Bn9YQlEA.js`),__vite__mapDeps([39,2,3,35,36,40]))};function OZ(e){let t=DZ[e];if(!t)throw Error(`Unknown builtin plugin module`);return t()}function kZ(e,t){return new Promise((n,r)=>{let i=document.createElement(`link`);i.rel=`stylesheet`,i.href=e;let a=()=>{t.removeEventListener(`abort`,o),i.onload=i.onerror=null,i.remove()},o=()=>{a(),r(Error(`Plugin stylesheet aborted`))};t.addEventListener(`abort`,o,{once:!0}),i.onload=()=>{t.removeEventListener(`abort`,o),i.onload=i.onerror=null,n(a)},i.onerror=()=>{a(),r(Error(`Plugin stylesheet failed to load`))},t.aborted?o():document.head.append(i)})}function AZ(e,t,n,r=0){let[i]=(0,P.useState)(()=>new EZ({loadModule:e=>e.startsWith(`builtin:`)?OZ(e):import(e),loadStyle:kZ})),a=(0,P.useSyncExternalStore)(i.subscribe,i.getSnapshot),o=(0,P.useRef)(new Map);a.sessionId&&a.ready&&o.current.set(a.sessionId,a.plugins.filter(e=>e.definition.workbench)),(0,P.useEffect)(()=>{if(e&&t)return globalThis.__PI_WEBAPP_REACT__=P,i.start(t,n),()=>i.dispose()},[i,e,t,r]);let s=e&&a.sessionId===t;return{plugins:s?a.plugins:!e&&t?o.current.get(t)??[]:[],errors:s?a.errors:[]}}var jZ=class extends P.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(e){console.error(`pi-webapp plugin ${this.props.id}:`,e)}render(){return this.state.failed?null:this.props.children}};function MZ(e,t){return{...e,invokeAction:(n,r)=>e.invokePluginAction(t,n,r),resolveInteraction:n=>!e.interaction||e.interaction.pluginId!==t?Promise.reject(Error(`No pending interaction`)):e.resolvePluginInteraction(t,e.interaction.requestId,n)}}function NZ({plugins:e,props:t}){let n=t.session?.interactions?.find(t=>e.some(e=>e.id===t.pluginId&&e.definition.interactions?.some(e=>e.kind===t.kind))),r=e.find(e=>e.id===n?.pluginId),i=r?.definition.interactions?.find(e=>e.kind===n?.kind)?.component;return!n||!r||!i?null:(0,F.jsx)(jZ,{id:r.id,children:(0,F.jsx)(i,{...MZ({...t,interaction:n},r.id)})},`${r.instanceId??r.id}/${n.requestId}`)}function PZ({plugins:e,props:t,call:n,result:r,running:i}){let a=e.flatMap(e=>(e.definition.workbench?.toolViews??[]).map(t=>({plugin:e,view:t}))).find(({view:e})=>e.tools.includes(n.toolName??``));if(!a)return null;let o=a.view.component;return(0,F.jsx)(jZ,{id:a.plugin.id,children:(0,F.jsx)(o,{...MZ(t,a.plugin.id),call:n,result:r,running:i})})}function FZ({plugins:e,slot:t,props:n}){let r=e.flatMap(e=>(e.definition.slots??[]).filter(e=>e.slot===t).map(t=>({plugin:e,item:t})));return r.sort((e,t)=>(e.item.order??0)-(t.item.order??0)||e.plugin.id.localeCompare(t.plugin.id)||e.item.id.localeCompare(t.item.id)),(0,F.jsx)(F.Fragment,{children:r.map(({plugin:e,item:t})=>{let r=t.component;return(0,F.jsx)(jZ,{id:e.id,children:(0,F.jsx)(r,{...MZ(n,e.id)})},`${e.instanceId??e.id}/${t.id}`)})})}function IZ(e,t=[]){let n=(0,P.useRef)(new Map),{controller:r,resources:i,owners:a}=(0,P.useMemo)(()=>{let t=e??``,r=n.current.get(t);if(!r){let e=e=>({id:e,kind:`guide`,contentId:`guide`,title:`开始`});r={controller:new sX({makeInitialTab:e,makePaneTab:e}),resources:new Map,owners:new Map};let i=r;i.controller.subscribe(()=>{let e=i.controller.getSnapshot().state.tabs;for(let[t,n]of i.resources)e[t]||(n.dispose?.(),i.resources.delete(t));for(let t of i.owners.keys())e[t]||i.owners.delete(t)}),n.current.set(t,r)}return r},[e]);(0,P.useEffect)(()=>{for(let[t,r]of n.current)for(let n of r.resources.values())n.activate?.(t===e)},[e]),(0,P.useEffect)(()=>{for(let e of n.current.values())for(let[n,r]of[...e.owners])t.includes(r)&&e.controller.closeTab(n)},[t]),(0,P.useEffect)(()=>()=>{for(let e of n.current.values())for(let t of e.resources.values())t.dispose?.()},[]);let o=(0,P.useSyncExternalStore)(r.subscribe,r.getSnapshot),s=gJ(o.state,o.state.activePaneId).activeTabId,c=s?vJ(o.state,s):void 0;return{controller:r,snapshot:o,panelId:c?.kind===`plugin`?c.contentId:null,resources:i,owners:a,expand:()=>{Object.keys(r.getSnapshot().state.tabs).length||r.openContent({kind:`guide`,contentId:`guide`,title:`开始`}),r.setExpanded(!0)},openContent:(0,P.useCallback)((e,t,n,i,o)=>{let s=r.getSnapshot().state,c=i&&gJ(s,i).host===`dock`?i:GY(s),l=gJ(s,c),u=l.activeTabId&&s.tabs[l.activeTabId]?.kind===`guide`?l.activeTabId:void 0,d=l.tabs.find(n=>s.tabs[n]?.kind===e&&s.tabs[n]?.contentId===t),f=d??r.openContent({kind:e,contentId:t,title:n,paneId:c,revealIfOpened:e!==`files`});return o&&a.set(f,o),d&&r.focusTab(d),u&&r.closeTab(u),r.setExpanded(!0),requestAnimationFrame(()=>document.querySelector(`[data-dockkit-content="${f}"]`)?.focus()),f},[r,a]),shown:o.state.expanded&&Object.keys(o.state.tabs).length>0}}function LZ({panel:e,width:t,narrow:n,focus:i,onExitFocus:a,plugins:o,props:s,cwd:c}){let{controller:l,snapshot:u,openContent:d}=e,{state:f}=u,[p,m]=(0,P.useState)(``),h=(0,P.useRef)(!1),g=(0,P.useMemo)(()=>new Proxy(l,{get(e,t){if(t===`closeTab`)return t=>{if(h.current)return;h.current=!0;let n=s.session?.sessionId??``;op.flush(n).then(async()=>{let r=document.querySelector(`[data-dockkit-content="${CSS.escape(t)}"]`);r&&await op.retireWithin(n,r),m(``),e.closeTab(t)}).catch(e=>m(e instanceof Error?e.message:String(e))).finally(()=>{h.current=!1})};let n=Reflect.get(e,t,e);return typeof n==`function`?n.bind(e):n}}),[l,s.session?.sessionId]),_=n||f.mode===`fullscreen`,v=s.locale===`zh`?_Z:vZ,y=e=>v[e]??e,b=e=>typeof e==`string`?e:e[s.locale],x=o.flatMap(e=>(e.definition.workbench?.panels??[]).map(t=>({plugin:e,contribution:t}))),S=()=>{a(),l.setExpanded(!1),requestAnimationFrame(()=>document.querySelector(`[data-sidebar-right-expand]`)?.focus())},C=n?`100vw`:t;return(0,F.jsx)(`div`,{className:fZ.panel,style:{width:C,"--dsh-sidebar-width":typeof C==`number`?`${C}px`:C},"data-sidebar-right-session":s.session?.sessionId,"data-sidebar-right-panel":_?`fullscreen`:i?`focus`:`push`,"data-sidebar-right-open":e.shown||void 0,"aria-hidden":!e.shown||void 0,children:(0,F.jsxs)(`div`,{className:fZ.panelBody,children:[p&&(0,F.jsx)(`p`,{role:`alert`,children:p}),(0,F.jsx)(dZ,{state:f,canSplit:u.canSplit&&wJ(f).length<2,dropZones:`horizontal`,minPaneFraction:.2,intents:g,labels:gZ(y),active:!0,keepMounted:()=>!0,renderTab:t=>{let n=CJ(f,t.id).id,i=f.expanded&&gJ(f,n).activeTabId===t.id;if(t.kind===`guide`)return(0,F.jsx)(`div`,{className:ue.guide,children:(0,F.jsxs)(`div`,{className:ue.guideGrid,role:`group`,"aria-label":r(`工作区工具`,`Workspace tools`),children:[o.map(e=>{let t=e.definition.workbench?.entry;if(!t)return null;let r=t.icon;return(0,F.jsxs)(`button`,{type:`button`,className:ue.guideEntry,disabled:!s.session||!c,"aria-label":b(t.label),onClick:()=>d(t.kind,t.multiple?ge():`workspace`,b(t.panelTitle??t.label),n,e.id),children:[(0,F.jsx)(`span`,{className:ue.guideIcon,"aria-hidden":`true`,children:(0,F.jsx)(r,{size:24})}),(0,F.jsxs)(`span`,{className:ue.guideCopy,children:[(0,F.jsx)(`span`,{className:ue.guideLabel,children:b(t.label)}),(0,F.jsx)(`span`,{className:ue.guideDescription,children:b(t.description)})]})]},e.id)}),!o.some(e=>e.definition.workbench?.entry)&&(0,F.jsx)(`p`,{className:ue.state,children:r(`没有已启用的工作区插件,可在设置中启用。`,`No workspace plugins enabled. Enable one in Settings.`)})]})});let a=x.find(e=>e.contribution.kind===t.kind);if(a&&s.session){let{plugin:r,contribution:o}=a;e.owners.set(t.id,r.id);let c=o.component;return(0,F.jsx)(jZ,{id:r.id,children:(0,F.jsx)(c,{sendMessage:s.sendMessage,session:s.session,locale:s.locale,visible:i,contentId:t.contentId,title:t.title,renderMarkdown:s.renderMarkdown,resource:(n,r,i)=>{let a=e.resources.get(t.id);if(!a){let o=n();a={value:o,dispose:()=>r?.(o),activate:e=>i?.(o,e)},e.resources.set(t.id,a)}return a.value},open:(e,t,i)=>d(e,t,i,n,r.id)})})}return(0,F.jsx)(FZ,{plugins:o,slot:`rightbar.panel`,props:{...s,panelId:t.contentId}})},renderTabTitle:e=>{if(e.kind===`guide`)return y(`tab.guide.title`);let t=x.find(t=>t.contribution.kind===e.kind);return t?(0,F.jsx)(`span`,{className:ue.title,children:t.contribution.title?.(e.contentId,e.title)??e.title}):(0,F.jsx)(FZ,{plugins:o,slot:`rightbar.title`,props:{...s,panelId:e.contentId}})},chrome:(0,F.jsx)(hZ,{sessionId:s.session?.sessionId??``,fullscreen:_||i,focus:i,shortcuts:[],t:y,actions:{toggleExpanded:S},toggleFullscreen:()=>i?a():n?S():l.setMode(_?`push`:`fullscreen`)})})]})})}function RZ({panel:e,locale:t}){if(e.shown)return null;let n=t===`zh`?_Z:vZ;return(0,F.jsx)(hO,{label:n[`chrome.expand`],side:`bottom`,delayMs:500,children:(0,F.jsx)(bZ,{size:`sm`,className:xZ.button,"aria-label":n[`chrome.expandAria`],"data-sidebar-right-expand":!0,onClick:e.expand,children:(0,F.jsx)(te,{className:xZ.icon})})})}function zZ(e,t){let n=e.filter(e=>e.enabled&&e.generation!==void 0&&e.contribution&&e.documentUrl&&e.controllerUrl).map(e=>{let n=t.find(t=>t.pluginId===e.pluginId);return n&&n.generation===e.generation&&n.name===e.name&&n.icon===e.icon&&n.documentUrl===e.documentUrl&&n.controllerUrl===e.controllerUrl&&JSON.stringify(n.contribution)===JSON.stringify(e.contribution)?n:e});return n.length===t.length&&n.every((e,n)=>e===t[n])?t:n}var BZ=`pi:hosted:unconfirmed-views:v1`,VZ=`pi:hosted:unconfirmed-view:v1:`,HZ=`pi:hosted:retired-view:v1:`,UZ=``,WZ=()=>{UZ=`View recovery journal could not be read. Its original data has been retained.`},GZ=()=>{UZ=`View recovery journal could not be stored. Keep this page open and download local drafts.`};function KZ(e){if(!e||typeof e!=`object`)return!1;let t=e;return[`controller`,`workspace`,`editor`,`tool`].includes(String(t.kind))&&[`sessionId`,`pluginId`,`mountId`,`viewToken`].every(e=>typeof t[e]==`string`&&t[e].length>0&&t[e].length<=214)&&Number.isSafeInteger(t.generation)&&Number(t.generation)>=1&&(t.contentId===void 0||typeof t.contentId==`string`)&&(t.createdAt===void 0||Number.isSafeInteger(t.createdAt))&&[`retained`,`frameStarted`].every(e=>t[e]===void 0||typeof t[e]==`boolean`)&&(t.backups===void 0||Array.isArray(t.backups)&&t.backups.every(e=>e&&typeof e.key==`string`&&typeof e.name==`string`))}function qZ(){try{if(typeof sessionStorage>`u`)return[];let e=sessionStorage.getItem(BZ);if(!e)return[];let t=JSON.parse(e);if(!Array.isArray(t)||!t.every(KZ))throw Error(`Invalid view recovery journal`);return t}catch{return WZ(),[]}}function JZ(e){if(typeof localStorage>`u`)return null;let t=localStorage.getItem(HZ+e);if(t!==null){if(JSON.parse(t)!==!0)throw Error(`Invalid view retirement receipt`);return`retired`}let n=localStorage.getItem(VZ+e);if(!n)return null;let r=JSON.parse(n);if(!KZ(r)||r.viewToken!==e)throw Error(`Invalid durable view recovery record`);return r}function YZ(e,t){return e.sessionId===t.sessionId&&e.pluginId===t.pluginId&&e.generation===t.generation&&e.mountId===t.mountId}var XZ=qZ(),ZZ=new Set(XZ.map(e=>e.viewToken));function QZ(){let e=new Map(XZ.map(e=>[e.viewToken,e]));try{if(typeof localStorage<`u`)for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t),r=n?.startsWith(VZ)?VZ:n?.startsWith(HZ)?HZ:void 0;if(!r)continue;let i=n.slice(r.length);try{let t=JZ(i);if(t===`retired`)e.delete(i);else if(t){let n=e.get(i);if(n&&!YZ(n,t))throw Error(`Conflicting view recovery identity`);e.set(i,{...t,discovered:!ZZ.has(i)})}}catch{WZ()}}}catch{WZ()}return[...e.values()]}var $Z=QZ(),eQ=[...$Z];function tQ(){return eQ=eQ.filter(e=>{try{return JZ(e.viewToken)!==`retired`}catch{return WZ(),!0}}),eQ.filter(e=>$Z.some(t=>t.viewToken===e.viewToken))}var nQ=new Map,rQ=`pi:hosted:recovery-draft:v1:`,iQ=()=>UZ;function aQ(){if(UZ)return!1;try{return typeof sessionStorage<`u`&&sessionStorage.setItem(BZ,JSON.stringify(eQ.filter(e=>ZZ.has(e.viewToken)))),!0}catch{return GZ(),!1}}function oQ(e){if(UZ)return!1;try{if(typeof localStorage>`u`)return!0;let t=JZ(e.viewToken);if(t===`retired`)return!1;if(t&&!YZ(t,e))throw Error(`Conflicting view recovery identity`);let{discovered:n,...r}={...e,...t?.frameStarted?{frameStarted:!0}:{},...t?.retained?{retained:!0}:{},backups:[...new Map([...t?.backups??[],...e.backups??[]].map(e=>[e.key,e])).values()]};return localStorage.setItem(VZ+e.viewToken,JSON.stringify(r)),!0}catch{return GZ(),!1}}function sQ(e,t,n){ZZ.add(t),eQ=eQ.filter(e=>e.viewToken!==t);let r={...e,viewToken:t,kind:n.kind,contentId:n.contentId,frameStarted:!1,createdAt:Date.now()};eQ.push(r),oQ(r),aQ()}function cQ(e){let t=eQ.find(t=>t.viewToken===e);if(!t||t.retained)return!1;let n={...t,frameStarted:!0};return oQ(n)?(eQ=eQ.map(t=>t.viewToken===e?n:t),aQ()):!1}function lQ(e){eQ=eQ.filter(t=>t.viewToken!==e),ZZ.delete(e);try{JZ(e),typeof localStorage<`u`&&localStorage.setItem(HZ+e,JSON.stringify(!0))}catch{WZ()}aQ()}async function uQ(e){if(e.discovered&&(e.kind===`controller`||e.frameStarted!==!0))return;let t=(await qk.view({...e,operation:`reconcile`})).recovery;return t?.state===`unconfirmed`&&e.frameStarted===!1&&ZZ.has(e.viewToken)&&(await qk.view({...e,operation:`cancel-initialization`}),lQ(e.viewToken),t={...t,state:`retired`}),(t?.state===`retired`||t?.state===`absent`&&e.kind===`controller`)&&lQ(e.viewToken),t}var dQ=3e5,fQ=new Set([`invalid_scope`,`unknown_plugin`]),pQ=`@chengzhiyi/pi-excalidraw`;function mQ(e){if(!Array.isArray(e))return;let t=e.filter(e=>e&&typeof e==`object`&&!e.isDeleted).map(e=>[String(e.id),e.version,e.versionNonce]);return JSON.stringify(t.sort((e,t)=>e[0]<t[0]?-1:+(e[0]>t[0])))}async function hQ(e,t){if(e.kind===`controller`)return!0;let n=yQ(e);if(!n.length)return!0;if(e.pluginId!==pQ||t===void 0)return!1;for(let r of n){let n=/^recovery-(.+)\.excalidraw$/.exec(r.name)?.[1];if(!n)return!1;try{let i=await qk.action({sessionId:e.sessionId,pluginId:e.pluginId,generation:t,action:`get`,input:{id:n}}),a=mQ(JSON.parse(r.json).elements);if(!a||a!==mQ(i?.scene?.elements))return!1}catch{return!1}}return!0}async function gQ(e,t,n=Date.now()){if(e.retained)return{state:`retained`};let r=e.frameStarted===!0||e.createdAt===void 0||n-e.createdAt>dQ,i=async()=>await hQ(e,t)?(lQ(e.viewToken),!0):!1,a;try{a=(await qk.view({...e,operation:`status`})).recovery}catch(t){let n=t?.code;if(r&&typeof n==`string`&&fQ.has(n)&&await i())return{state:`retired`};if(t instanceof Error&&t.message===`Unknown view operation`)return uQ(e);throw t}if(a?.state===`retired`)return lQ(e.viewToken),a;if(a?.state===`absent`)return r&&await i()?{state:`retired`}:r||e.discovered?a:uQ(e);if(a?.state===`unconfirmed`&&a.stale){if(e.kind===`controller`)return uQ({...e,discovered:!1});if(!a.dirty&&!a.busy&&await hQ(e,t))try{return await qk.view({...e,operation:`close`}),lQ(e.viewToken),{state:`retired`}}catch{return a}return a}return a?.state===`unconfirmed`&&!e.discovered?uQ(e):a}async function _Q(e){let t=await qk.view({...e,operation:`recover`,confirmation:`retain-unconfirmed-edits`});if(t.recovery?.state===`retired`){lQ(e.viewToken);return}if(!t.recovery||![`retained`,`absent`].includes(t.recovery.state))throw Error(`This view still has an active operation. Its recovery state was preserved.`);eQ=eQ.map(t=>t.viewToken===e.viewToken?{...t,retained:!0}:t);let n=eQ.find(t=>t.viewToken===e.viewToken);n&&oQ(n),aQ()}async function vQ(e){(await qk.view({...e,operation:`reconcile`})).recovery?.state!==`absent`&&await qk.view({...e,operation:`discard`,confirmation:`discard-unconfirmed-edits`}),lQ(e.viewToken)}function yQ(e){if(e.pluginId!==`@chengzhiyi/pi-excalidraw`)return[];let t=`pi-diagram:${e.sessionId}:`,n=[];try{if(typeof localStorage>`u`)return[];for(let t of e.backups??[]){if(!t.key.startsWith(`${rQ}${e.viewToken}:`))continue;let r=nQ.get(t.key)??localStorage.getItem(t.key);r&&n.push({name:t.name,json:r})}if(n.length)return n;for(let r=0;r<localStorage.length;r++){let i=localStorage.key(r);if(!i?.startsWith(t)||e.contentId&&i!==t+e.contentId)continue;let a=localStorage.getItem(i);if(!(!a||a.length>16777216))try{let e=JSON.parse(a);if(!e||!Array.isArray(e.elements))continue;let r=i.slice(t.length).replace(/[^\w.-]/g,`_`).slice(0,100);n.push({name:`recovery-${r}.excalidraw`,json:a})}catch{}}}catch{}return n}for(let e of $Z){if(e.kind===`controller`)continue;let t=yQ(e);t.length&&(e.backups=t.map(t=>{let n=`${rQ}${e.viewToken}:${t.name}`;nQ.set(n,t.json);try{localStorage.getItem(n)||localStorage.setItem(n,t.json)}catch{UZ=`Recovery copy could not be stored. Keep this page open and download local drafts before reloading.`}return{key:n,name:t.name}}))}for(let e of eQ)oQ(e);aQ();function bQ(e){let t=e;if(!t||!(t.blob instanceof Blob)||!t.blob.size||t.blob.size>16777216||typeof t.name!=`string`||t.name.length>200||/[/\\\x00-\x1f\x7f]/.test(t.name))throw Error(`Invalid drawing download`);let n={png:`image/png`,svg:`image/svg+xml`,excalidraw:`application/json`,json:`application/json`}[t.name.split(`.`).pop()?.toLowerCase()??``];if(!n||t.blob.type!==n)throw Error(`Unsupported drawing download`);return{blob:t.blob,name:t.name}}function xQ(e){let{blob:t,name:n}=bQ(e),r=URL.createObjectURL(t),i=document.createElement(`a`);i.href=r,i.download=n,i.hidden=!0,document.body.append(i);try{i.click()}finally{i.remove(),setTimeout(()=>URL.revokeObjectURL(r),3e4)}}var SQ={entry:`_entry_ic7m3_1`,trigger:`_trigger_ic7m3_3`,dialog:`_dialog_ic7m3_5`,content:`_content_ic7m3_8`,list:`_list_ic7m3_10`,item:`_item_ic7m3_11`,error:`_error_ic7m3_14`,history:`_history_ic7m3_20`,actions:`_actions_ic7m3_24`};function CQ({sessionId:e,locale:t,openRecovered:n}){let[r,i]=(0,P.useState)(tQ),[a,o]=(0,P.useState)(!1),[s,c]=(0,P.useState)(null),[l,u]=(0,P.useState)(``),[d,f]=(0,P.useState)(!1),[p,m]=(0,P.useState)(0),h=(e,n)=>t===`zh`?e:n,[g,_]=(0,P.useState)(new Set),[v,y]=(0,P.useState)(new Set),b=r.filter(e=>v.has(e.viewToken)&&!g.has(e.viewToken)),x=iQ(),S=e=>{lQ(e),i(t=>t.filter(t=>t.viewToken!==e))};if((0,P.useEffect)(()=>{o(!1),c(null),u(``)},[e]),(0,P.useEffect)(()=>{let e=!0;return(async()=>{let t=new Map;try{t=new Map((await qk.catalog()).plugins.flatMap(e=>e.generation===void 0?[]:[[e.pluginId,e.generation]]))}catch{}let n=e=>y(t=>new Set(t).add(e));for(let a of r){if(!e)return;try{let r=await gQ(a,t.get(a.pluginId));if(!e)return;r?.state===`retired`||r?.state===`absent`&&a.kind===`controller`?S(a.viewToken):r?.state===`retained`&&i(e=>e.map(e=>e.viewToken===a.viewToken?{...e,retained:!0}:e)),_(e=>{let t=new Set(e);return a.discovered&&r?.state===`unconfirmed`&&r.stale===!1?t.add(a.viewToken):t.delete(a.viewToken),t}),n(a.viewToken)}catch(t){if(!e)return;if(t instanceof Error&&t.message===`Unknown view operation`){y(new Set(r.map(e=>e.viewToken)));return}n(a.viewToken),u(String(t))}}})(),()=>{e=!1}},[e,p]),!b.length&&!x)return null;let C=e=>({controller:h(`后台控制器`,`Controller`),workspace:h(`工作区`,`Workspace`),editor:h(`编辑器`,`Editor`),tool:h(`工具预览`,`Tool preview`)})[e]??h(`插件视图`,`Plugin view`),w=s?.operation===`retain`;return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`div`,{className:SQ.entry,"data-hosted-recovery":!0,children:[(0,F.jsx)(`p`,{children:h(`刷新或关闭窗口后,旧插件视图可能尚未完成保存和关闭确认;部分记录也可能属于仍打开的窗口。请先核对原窗口及备份,再保留失联视图的恢复记录,解除升级等操作的阻塞。`,`After reloading or closing a window, previous plugin views may lack save and close confirmations. Some records may belong to windows still open. Check original windows and backups, then retain disconnected views for recovery to unblock updates and other operations.`)}),(0,F.jsxs)(`button`,{type:`button`,className:SQ.trigger,"aria-haspopup":`dialog`,onClick:()=>o(!0),children:[h(`插件视图恢复`,`Plugin view recovery`),` · `,b.length]})]}),(0,F.jsx)(OO,{open:a,onClose:()=>o(!1),title:h(`检查之前的插件视图`,`Review previous plugin views`),closeLabel:h(`关闭`,`Close`),className:SQ.dialog,footer:(0,F.jsx)(EO,{variant:`outline`,disabled:d,onClick:()=>{u(``),m(e=>e+1)},children:h(`重新检查`,`Check again`)}),children:(0,F.jsxs)(`div`,{className:SQ.content,children:[(0,F.jsx)(`p`,{children:h(`以下列出所有会话中待确认的旧插件视图。请先检查原窗口、编辑器和本地备份,只处理已失联的视图;仍打开的窗口请先正常保存并关闭。`,`These are previous plugin views awaiting confirmation across all sessions. Check original windows, editors and local backups. Only recover disconnected views; save and close windows that remain open first.`)}),(0,F.jsx)(`p`,{children:h(`保留恢复记录会停止旧视图继续写入,不会覆盖当前图稿。丢弃未确认的记录不会保存或恢复图稿,无法找回的最新修改可能永久丢失。`,`Retaining recovery records stops old views writing without overwriting the current drawing. Discarding unconfirmed records does not save or restore a drawing; unrecoverable recent edits may be permanently lost.`)}),(0,F.jsx)(`div`,{className:SQ.list,children:b.map((t,r)=>(0,F.jsxs)(`section`,{className:SQ.item,"data-unconfirmed-view":t.mountId,children:[(0,F.jsxs)(`h3`,{children:[C(t.kind),` `,r+1]}),t.retained&&(0,F.jsx)(`p`,{children:h(`失联视图的恢复记录已保留。插件可继续操作;旧稿是否完整仍需核对。`,`Disconnected view recovery record retained. Plugin operations may continue; the old draft still needs verification.`)}),(0,F.jsxs)(`details`,{children:[(0,F.jsx)(`summary`,{children:h(`视图信息`,`View details`)}),(0,F.jsxs)(`dl`,{children:[(0,F.jsx)(`dt`,{children:h(`会话`,`Session`)}),(0,F.jsx)(`dd`,{children:t.sessionId}),(0,F.jsx)(`dt`,{children:h(`插件`,`Plugin`)}),(0,F.jsx)(`dd`,{children:t.pluginId}),(0,F.jsx)(`dt`,{children:h(`版本代次`,`Generation`)}),(0,F.jsx)(`dd`,{children:t.generation}),(0,F.jsx)(`dt`,{children:h(`视图标识`,`View ID`)}),(0,F.jsx)(`dd`,{children:t.mountId}),t.contentId&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`dt`,{children:h(`内容标识`,`Content ID`)}),(0,F.jsx)(`dd`,{children:t.contentId})]})]})]}),(0,F.jsxs)(`div`,{className:SQ.actions,children:[yQ(t).map(e=>(0,F.jsxs)(EO,{variant:`outline`,disabled:d,onClick:()=>xQ({blob:new Blob([e.json],{type:`application/json`}),name:e.name}),children:[h(`下载本地恢复副本`,`Download local recovery copy`),` · `,e.name]},e.name)),t.contentId&&t.sessionId===e&&n&&(0,F.jsx)(EO,{variant:`outline`,disabled:d,onClick:()=>{o(!1),n(t.contentId)},children:h(`打开图稿并核对备份`,`Open drawing and compare backup`)}),!t.retained&&(0,F.jsx)(EO,{variant:`outline`,disabled:d,onClick:()=>c({item:t,operation:`retain`}),children:h(`保留恢复记录并解除阻塞`,`Retain recovery record and unblock`)}),(0,F.jsx)(EO,{variant:`outline`,disabled:d,onClick:()=>c({item:t,operation:`discard`}),children:h(`丢弃此视图的未确认修改`,`Discard this view's unconfirmed edits`)})]})]},t.viewToken))}),(l||x)&&(0,F.jsxs)(`div`,{role:`alert`,className:SQ.error,children:[h(`未能确认部分视图,请保留恢复记录并重试。`,`Some views could not be verified. Keep their recovery records and retry.`),(0,F.jsxs)(`details`,{children:[(0,F.jsx)(`summary`,{children:h(`诊断信息`,`Diagnostics`)}),l||x]})]})]})}),(0,F.jsx)(OO,{open:!!s&&a,onClose:()=>c(null),title:w?h(`保留此视图用于恢复?`,`Retain this view for recovery?`):h(`丢弃此视图的未确认修改?`,`Discard this view's unconfirmed edits?`),closeLabel:h(`关闭`,`Close`),description:w?h(`请先确认旧视图已失联并核对备份。此操作保留恢复记录和本地副本,停止旧视图继续写入,不会保存、覆盖或丢弃图稿。`,`First confirm the old view is disconnected and review backups. This preserves recovery records and local copies and stops the old view writing, without saving, overwriting or discarding a drawing.`):h(`请先确认原标签页已关闭,并下载可恢复的草稿。此操作不会保存或恢复内容;无法找回的修改可能永久丢失。`,`First confirm the original tab is closed and download any recoverable draft. This does not save or restore content; unrecovered edits may be permanently lost.`),footer:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(EO,{variant:`outline`,disabled:d,onClick:()=>c(null),children:h(`取消`,`Cancel`)}),(0,F.jsx)(EO,{variant:`primary`,disabled:d,onClick:()=>{if(!s||d)return;let{item:e,operation:t}=s;f(!0),u(``),(t===`retain`?_Q(e):vQ(e)).then(()=>{t===`retain`?i(tQ()):S(e.viewToken),c(null)}).catch(e=>{u(String(e)),c(null)}).finally(()=>f(!1))},children:w?h(`保留恢复记录`,`Retain record`):h(`确认丢弃`,`Discard edits`)})]})})]})}var wQ=new class{entries=new Set;releaseLock;timer;running=!1;interval;request;constructor(e=250,t=async e=>{let t=new AbortController,n=setTimeout(()=>t.abort(),5e3);try{return await Kk(`/views`,{operation:`pollMany`,views:e},t.signal)}finally{clearTimeout(n)}}){this.interval=e,this.request=t}add(e){return this.entries.add(e),this.holdLock(),this.schedule(0),()=>{this.entries.delete(e),this.entries.size||(this.timer&&=(clearTimeout(this.timer),void 0),this.releaseLock?.())}}holdLock(){if(this.releaseLock||typeof navigator>`u`||!navigator.locks)return;let e,t=new Promise(t=>{e=t});this.releaseLock=()=>{this.releaseLock=void 0,e()},navigator.locks.request(`pi:hosted:view-poller:${crypto.randomUUID()}`,()=>t).catch(()=>{this.releaseLock=void 0})}wake(){!this.running&&this.entries.size&&(this.timer&&=(clearTimeout(this.timer),void 0),this.schedule(0))}schedule(e){this.running||this.timer||!this.entries.size||(this.timer=setTimeout(()=>{this.timer=void 0,this.tick()},e))}async tick(){this.running=!0;let e=[...this.entries];try{for(let t=0;t<e.length;t+=64){let n=e.slice(t,t+64).filter(e=>this.entries.has(e));if(!n.length)continue;let{replies:r}=await this.request(n.map(e=>e.input()));if(!Array.isArray(r)||r.length!==n.length)throw Error(`Invalid aggregate view reply`);await Promise.all(n.map(async(e,t)=>{if(this.entries.has(e))try{let n=r[t];if(n.failure)throw Object.assign(Error(n.failure.body.error),{status:n.failure.status});if(!n.reply||n.reply.viewToken!==e.input().viewToken)throw Error(`Mismatched view reply`);await e.accept(n.reply)}catch(t){this.entries.delete(e),e.fail(t)}}))}}catch(t){for(let n of e)this.entries.delete(n)&&n.fail(t)}finally{this.running=!1,this.schedule(this.interval)}}};typeof document<`u`&&document.addEventListener(`visibilitychange`,()=>{document.hidden||wQ.wake()});var TQ=class{token=``;get capability(){return{viewToken:this.token,mountId:this.identity.mountId}}stopped=!1;closed=!1;closing;abort=new AbortController;unlisten;after=0;snapshot;frozen=!1;localCloseCheckpoint=!1;frameStarted=!1;connecting(){if(!cQ(this.token)&&this.mount.kind!==`controller`)throw Error(`Cannot protect the editor recovery journal; download local drafts before opening another editor`);this.frameStarted=!0}async flushed(){await this.changed({dirty:!1,busy:!1})}identity;adapter;mount;reconnect;failed;poller;constructor(e,t,n,r,i,a=wQ){this.poller=a,this.identity=e,this.adapter=t,this.mount=n,this.reconnect=r,this.failed=i}async start(){this.token=crypto.randomUUID(),sQ(this.identity,this.token,this.mount);let e=await qk.view({...this.identity,operation:`register`,kind:this.mount.kind,viewToken:this.token});e.viewToken!==this.token&&(lQ(this.token),this.token=e.viewToken,sQ(this.identity,this.token,this.mount))}listen(){this.stopped||this.unlisten||(this.unlisten=this.poller.add({input:()=>({...this.identity,viewToken:this.token,operation:`poll`,after:this.after}),accept:e=>this.receive(e),fail:e=>{this.stopped||this.failed(e)}}))}retry(){if(this.closed)throw Error(`Closed view cannot reconnect`);this.unlisten?.(),this.unlisten=void 0,this.stopped=!1,this.abort=new AbortController,this.localCloseCheckpoint?this.adapter.call(`restore`,this.snapshot).then(()=>{this.frozen=!1,this.localCloseCheckpoint=!1,this.listen()}).catch(this.failed):this.listen()}request(e){return qk.view({...this.identity,viewToken:this.token,...e},this.abort.signal)}async changed(e){let t=e;if(typeof t?.dirty!=`boolean`||typeof t.busy!=`boolean`)throw Error(`Invalid frame status`);await this.request({operation:`change`,dirty:t.dirty,busy:t.busy})}async receive(e){for(let t of e.commands){if(this.stopped)return;let e;try{if(t.type===`freeze`&&!this.frozen&&(this.snapshot=await this.adapter.call(`freeze`),this.frozen=!0),t.type===`resume`&&this.frozen&&(await this.adapter.call(`restore`,this.snapshot),this.frozen=!1),t.type===`committed`){await this.request({operation:`ack`,commandId:t.id,ok:!0}),await this.close(),this.reconnect();return}}catch(t){e=t}await this.request({operation:`ack`,commandId:t.id,ok:!e,...e?{error:e instanceof Error?e.message:String(e)}:{}}),this.after=t.id,e&&this.failed(e)}}close(){return this.closed?Promise.resolve():(this.closing||=(this.stopped=!0,this.unlisten?.(),this.abort.abort(),(async()=>{this.token&&(this.mount.kind!==`controller`&&!this.frameStarted?await qk.view({...this.identity,viewToken:this.token,operation:`cancel-initialization`}):(this.mount.kind!==`controller`&&!this.frozen&&(this.snapshot=await this.adapter.call(`freeze`),this.frozen=!0,this.localCloseCheckpoint=!0),this.localCloseCheckpoint&&await qk.view({...this.identity,viewToken:this.token,operation:`change`,dirty:!1,busy:!1}),await qk.view({...this.identity,viewToken:this.token,operation:`close`})),this.closed=!0,lQ(this.token))})().catch(e=>{throw this.closing=void 0,e})),this.closing)}},EQ={card:`_card_1g0je_1`,header:`_header_1g0je_2`,toggle:`_toggle_1g0je_6`,title:`_title_1g0je_7`,status:`_status_1g0je_8`,chevron:`_chevron_1g0je_9`,parameters:`_parameters_1g0je_12`,preview:`_preview_1g0je_13`,dialog:`_dialog_1g0je_15`,details:`_details_1g0je_18`};function DQ({title:e,tool:t,locale:n,children:r}){let[i,a]=(0,P.useState)(!1),[o,s]=(0,P.useState)(!1),c=(0,P.useId)(),l=(e,t)=>n===`zh`?e:t,u=t.result?.blocks.filter(e=>e.kind===`text`).map(e=>e.text??``).join(`
|
|
501
501
|
`);return(0,F.jsxs)(`article`,{className:e?EQ.card:void 0,"data-hosted-tool-card":e?``:void 0,children:[e&&(0,F.jsxs)(`header`,{className:EQ.header,children:[(0,F.jsxs)(`button`,{type:`button`,className:EQ.toggle,"aria-label":l(`展开或收起预览`,`Toggle preview`),"aria-expanded":!i,"aria-controls":c,onClick:()=>a(e=>!e),children:[(0,F.jsx)(`span`,{className:EQ.title,children:e}),(0,F.jsx)(`span`,{className:EQ.status,children:t.result?.isError?l(`失败`,`Failed`):t.result?l(`已完成`,`Completed`):t.running?l(`运行中`,`Running`):l(`未完成`,`Incomplete`)}),(0,F.jsx)(`span`,{className:EQ.chevron,"data-collapsed":i,"aria-hidden":`true`,children:(0,F.jsx)(ct,{size:16})})]}),(0,F.jsx)(`button`,{type:`button`,className:EQ.parameters,"aria-haspopup":`dialog`,onClick:()=>s(!0),children:l(`查看参数`,`View parameters`)})]}),(0,F.jsx)(`div`,{id:c,hidden:!!e&&i,className:EQ.preview,children:r}),(0,F.jsx)(OO,{open:o&&!!e,onClose:()=>s(!1),title:l(`工具参数`,`Tool parameters`),closeLabel:l(`关闭`,`Close`),className:EQ.dialog,children:(0,F.jsxs)(`div`,{className:EQ.details,"data-tool-parameters":!0,children:[(0,F.jsx)(`h3`,{children:l(`输入参数`,`Input`)}),(0,F.jsx)(`pre`,{tabIndex:0,children:t.call.text}),u!==void 0&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`h3`,{children:l(`工具结果`,`Result`)}),(0,F.jsx)(`pre`,{tabIndex:0,children:u})]})]})})]})}function OQ(e){let t=e;if(typeof t?.title!=`string`||!t.title.trim()||t.title.length>160)throw Error(`Invalid tool presentation`);return{title:t.title}}function kQ(e){let t=e?.height;if(typeof t!=`number`||!Number.isFinite(t)||t<0||t>4096)throw Error(`Invalid tool height`);return Math.max(1,Math.ceil(t))}function AQ(e){let t=e;if(typeof t?.message!=`string`||t.message.length>4e3||t.level!==`info`&&t.level!==`error`)throw Error(`Invalid notification`);return{message:t.message,level:t.level}}function jQ({card:e,mount:t,update:n,open:r,sendMessage:i,reconnect:a,abort:o}){let s=(0,P.useRef)(null),c=(0,P.useRef)(null),l=(0,P.useRef)(null),u=(0,P.useRef)(Promise.resolve()),d=(0,P.useRef)({open:r,sendMessage:i,reconnect:a,abort:o});d.current={open:r,sendMessage:i,reconnect:a,abort:o};let[f,p]=(0,P.useState)(``),[m,h]=(0,P.useState)(),[g,_]=(0,P.useState)(240),[v,y]=(0,P.useState)(),[b,x]=(0,P.useState)(MQ);(0,P.useEffect)(()=>{let e=new MutationObserver(()=>x(MQ()));return e.observe(document.body,{attributes:!0,attributeFilter:[`data-ds-dark-theme`]}),()=>e.disconnect()},[]),(0,P.useEffect)(()=>{if(!s.current||e.generation===void 0)return;let r={pluginId:e.pluginId,generation:e.generation,sessionId:t.sessionId,mountId:crypto.randomUUID()},i=!0,a=e=>{i&&p(e instanceof Error?e.message:String(e))},o,f=new ap(s.current,r,async(n,a)=>{if(!i)throw Error(`Frame mount cancelled`);let s=a;if(n===`toolPresentation`&&t.kind===`tool`)return h(OQ(a)),null;if(n===`resize`&&t.kind===`tool`)return _(kQ(a)),null;if(n===`notify`)return y(AQ(a)),null;if(n===`action`){if(typeof s?.action!=`string`)throw Error(`Invalid action`);return qk.action({sessionId:r.sessionId,pluginId:r.pluginId,generation:r.generation,...o.capability,action:s.action,input:s.input})}if(n===`downloadDrawing`&&[`editor`,`workspace`].includes(t.kind))return xQ(a),null;if(n===`changed`)return o.changed(a);if(n===`abort`&&d.current.abort)return await d.current.abort(),null;if(n===`openPanel`){if(typeof s?.kind!=`string`||!e.contribution?.panels.includes(s.kind)||typeof s.contentId!=`string`)throw Error(`Undeclared panel`);return d.current.open(s.kind,s.contentId,typeof s.title==`string`?s.title:e.name),null}if(n===`sendMessage`&&typeof s?.text==`string`)return await d.current.sendMessage(s.text),null;throw Error(`Unsupported frame host method: ${n}`)});o=new TQ(r,f,t,()=>d.current.reconnect(),a),c.current=f,l.current=o;let m=(async()=>{if(await o.start(),!i)throw Error(`Frame mount cancelled`);o.connecting(),await f.connect(t.kind===`controller`?e.controllerUrl:e.documentUrl,{...t,theme:MQ(),hostUi:{toolCard:!0,autoResize:!0,notifications:!0}}),o.listen()})();u.current=m;let g=op.add({identity:r,ready:m,adapter:f,afterFlush:()=>o.flushed(),toolCallId:n?.call?.toolCallId,retire:()=>o.close()});return m.catch(a),()=>{i=!1,g(),c.current=null,l.current=null,m.catch(()=>{}).then(()=>o.close()).catch(e=>console.error(`Hosted view cleanup did not acknowledge edits`,e)).finally(()=>f.dispose())}},[e.pluginId,e.generation,e.documentUrl,e.controllerUrl,t.sessionId,t.kind,t.contentId]),(0,P.useEffect)(()=>{u.current.then(()=>c.current?.call(`update`,{...t,...n??{},theme:b})).catch(e=>p(String(e)))},[n,t.locale,b,t.visible,t.title]);let S=(0,F.jsxs)(`div`,{"data-hosted-plugin":e.pluginId,style:{height:t.kind===`controller`||t.kind===`tool`?`auto`:`100%`,minHeight:0},children:[f&&(0,F.jsxs)(`p`,{role:`alert`,children:[f,` `,(0,F.jsx)(`button`,{type:`button`,onClick:()=>{try{l.current?.retry(),p(``)}catch(e){p(String(e))}},children:`Retry view connection`})]}),v&&(0,F.jsxs)(`p`,{role:v.level===`error`?`alert`:`status`,children:[v.message,(0,F.jsx)(`button`,{type:`button`,"aria-label":t.locale===`zh`?`关闭通知`:`Dismiss notification`,onClick:()=>y(void 0),children:`×`})]}),(0,F.jsx)(`iframe`,{hidden:t.kind===`controller`,ref:s,title:`${e.name} ${t.kind}`,style:{display:t.kind===`controller`?`none`:`block`,width:`100%`,height:t.kind===`tool`?g:`100%`,border:0}})]});return t.kind===`tool`?(0,F.jsx)(DQ,{title:m?.title,tool:n,locale:t.locale,children:S}):S}var MQ=()=>document.body.hasAttribute(`data-ds-dark-theme`)?`dark`:`light`;function NQ(e,t,n){let r=e.contribution,i=t=>`hosted:${e.pluginId}:${t}`;return{id:e.pluginId,instanceId:`${e.pluginId}/${e.generation}`,definition:{id:e.pluginId,apiVersion:1,activate(){},artifactTools:r.artifactTools,workbench:{apiVersion:1,entry:{...r.entry,kind:i(r.entry.kind),icon:t=>(0,F.jsx)(Zk,{card:e,...t})},panels:r.panels.map(a=>({kind:i(a),component:o=>(0,F.jsx)(jQ,{card:e,reconnect:t,abort:()=>n.current.abort?.()??Promise.reject(Error(`Abort unavailable`)),mount:{kind:a===r.entry.kind?`workspace`:`editor`,sessionId:o.session.sessionId,contentId:o.contentId,title:o.title,visible:o.visible,locale:o.locale,theme:MQ()},open:(e,t,n)=>o.open(i(e),t,n),sendMessage:o.sendMessage})})),toolViews:r.toolViews.length?[{tools:r.toolViews,component:i=>i.session?(0,F.jsx)(jQ,{card:e,reconnect:t,abort:()=>n.current.abort?.()??Promise.reject(Error(`Abort unavailable`)),mount:{kind:`tool`,sessionId:i.session.sessionId,locale:i.locale,theme:MQ()},update:{call:i.call,result:i.result,running:i.running},open:(e,t)=>i.openPanel(`${r.panelAlias.prefix}${t}`),sendMessage:i.sendMessage},op.incarnation(i.session.sessionId,i.call.toolCallId)):null}]:[],resolvePanel:e=>e.startsWith(r.panelAlias.prefix)?{kind:i(r.panelAlias.kind),contentId:e.slice(r.panelAlias.prefix.length),title:r.panelAlias.title}:null}}}}function PQ(e,t,n,r,i){let a=CQ({sessionId:t,locale:i,openRecovered:e=>r.current.openPanel?.(`diagram:${e}`)}),[o,s]=(0,P.useState)([]),[c,l]=(0,P.useState)([]),[u,d]=(0,P.useState)([]),[f,p]=(0,P.useState)(0),[m,h]=(0,P.useState)(``),g=(0,P.useMemo)(()=>()=>p(e=>e+1),[]);(0,P.useEffect)(()=>{if(!e||!t){s([]);return}let n=!0,r=new AbortController;return window.addEventListener(`pi:hosted-catalog-changed`,g),qk.catalog(r.signal).then(e=>{n&&(s(t=>zZ(e.plugins,t)),l(e.approvals??[]),e.offline||d(e.plugins.filter(e=>!e.installed||!e.enabled).map(e=>e.pluginId)),h(``))}).catch(()=>{}),()=>{n=!1,r.abort(),window.removeEventListener(`pi:hosted-catalog-changed`,g)}},[e,t,n,f]);let _=(0,P.useRef)(new WeakMap),v=(0,P.useMemo)(()=>o.map(e=>{let t=_.current.get(e);return t||(t=NQ(e,g,r),_.current.set(e,t)),t}),[o,g,r]),y=e&&t?o.map(e=>(0,F.jsx)(jQ,{card:e,reconnect:g,abort:()=>r.current.abort?.()??Promise.reject(Error(`Abort unavailable`)),mount:{kind:`controller`,sessionId:t,locale:i,theme:MQ()},open:(t,n)=>r.current.openPanel?.(`${e.contribution.panelAlias.prefix}${n}`),sendMessage:async e=>{if(!r.current.sendMessage)throw Error(`Composer unavailable`);await r.current.sendMessage(e)}},`${t}/${e.pluginId}/${e.generation}`)):null,b=(0,P.useCallback)((e,t)=>{qk.decide(e,t).then(e=>l(e.approvals??[])).catch(e=>h(String(e)))},[]);return{plugins:e?v:[],inactivePlugins:u,recovery:a,controllers:y,error:m,approvals:c,decide:b}}var FQ={zh:{title:`插件请求执行权限`,body:(e,t)=>`${e} 想让后台会话「${t}」获得写入与命令权限(此前只读)。`,allow:`允许`,deny:`拒绝`},en:{title:`A plugin requests permission to execute`,body:(e,t)=>`${e} wants background session "${t}" to gain write and command access (read-only until now).`,allow:`Allow`,deny:`Deny`}};function IQ({approvals:e,locale:t,decide:n}){let r=FQ[t];return e.length?(0,F.jsxs)(`section`,{role:`alertdialog`,"aria-label":r.title,style:{position:`fixed`,right:16,bottom:16,zIndex:1e3,maxWidth:420,padding:12,borderRadius:8,background:`var(--pi-surface, #fff)`,color:`var(--pi-text, #111)`,border:`1px solid var(--pi-border, #888)`,boxShadow:`0 4px 16px rgba(0,0,0,.25)`},children:[(0,F.jsx)(`strong`,{children:r.title}),e.map(e=>(0,F.jsxs)(`div`,{style:{marginTop:8},children:[(0,F.jsx)(`p`,{style:{margin:`0 0 6px`},children:r.body(e.pluginId,e.title)}),(0,F.jsx)(`button`,{type:`button`,onClick:()=>n(e.id,`allow`),children:r.allow}),` `,(0,F.jsx)(`button`,{type:`button`,onClick:()=>n(e.id,`deny`),children:r.deny})]},e.id))]}):null}var LQ=`@chengzhiyi/pi-excalidraw`,RQ=[`excalidraw_create_view`,`diagram_create`,`diagram_patch`];function zQ(e){let t=({locale:t})=>(0,F.jsxs)(`section`,{role:`status`,className:SQ.history,children:[(0,F.jsx)(`h3`,{children:`Excalidraw`}),(0,F.jsx)(`p`,{children:t===`zh`?`Excalidraw 编辑器当前不可用。请在插件管理中检查安装、启用状态及运行时诊断。未从历史工具参数重建图稿;原检查点、工作区文件和浏览器备份均保留。`:`The Excalidraw editor is currently unavailable. Check installation, enablement and runtime diagnostics in plugin management. Historical tool arguments are not the latest scene. Checkpoints, workspace files and browser backups are preserved.`}),(0,F.jsx)(EO,{variant:`outline`,onClick:e,children:t===`zh`?`打开插件管理`:`Open plugin management`})]});return{id:LQ,instanceId:`drawing-recovery`,definition:{id:LQ,apiVersion:1,activate(){},artifactTools:RQ,workbench:{apiVersion:1,panels:[{kind:`drawing-recovery`,component:t}],toolViews:[{tools:RQ,component:t}],resolvePanel:e=>/^diagram:[\w-]{1,80}$/.test(e)?{kind:`drawing-recovery`,contentId:e.slice(8),title:`Excalidraw`}:null}}}}function BQ(){let e=l(),t={"session.new.label":r(`新会话`,`New session`),"session.new":r(`新会话`,`New session`),"toggle.open":r(`展开侧栏`,`Expand sidebar`),"toggle.collapse":r(`收起侧栏`,`Collapse sidebar`),"sidebar.label":r(`对话管理`,`Conversation navigation`),"sidebar.close":r(`关闭侧栏`,`Close sidebar`),"panels.label":r(`面板`,`Panels`),"rightbar.drag.focus":r(`继续拖动以专注工作区`,`Keep dragging to focus workspace`),"rightbar.drag.collapse":r(`继续拖动以收起工作区面板`,`Keep dragging to collapse workspace panel`),"brand.localBuild":`pi-webapp`},n=EA(),i=(0,P.useRef)(n.session?.sessionId);i.current=n.session?.sessionId;let[a,o]=(0,P.useState)(``);(0,P.useEffect)(()=>o(``),[n.session?.sessionId]);let{plugins:s,errors:c}=AZ(n.connection===`connected`,n.session?.sessionId,n.plugins,n.pluginGeneration),u=(0,P.useRef)({}),f=PQ(n.connection===`connected`,n.session?.sessionId,n.pluginGeneration,u,e);Vt(`hosted-runtime`,f.error);let[p,m]=(0,P.useState)(!1),[h,g]=(0,P.useState)(!1),_=(0,P.useMemo)(()=>zQ(()=>g(!0)),[]),v=[...s,...f.plugins.filter(e=>!s.some(t=>t.id===e.id||t.definition.artifactTools?.some(t=>e.definition.artifactTools?.includes(t))))],y=v.some(e=>e.id===`@chengzhiyi/pi-excalidraw`)?v:[...v,_],b=(0,P.useMemo)(()=>[...n.disabledPlugins,...f.inactivePlugins],[n.disabledPlugins,f.inactivePlugins]),x=IZ(n.session?.sessionId,b),S=x.panelId,C=n.connection===`connected`&&n.session!==null&&n.modelsStatus===`ready`&&n.models.length===0;(0,P.useEffect)(()=>{C&&m(!0)},[C]);let w=(0,P.useCallback)(()=>{m(!1),requestAnimationFrame(()=>document.querySelector(`[aria-haspopup="dialog"].pi-settings-sidebar`)?.focus())},[]),[T,E]=(0,P.useState)(()=>({sidebar:280,viewportWidth:window.innerWidth,narrowExpanded:!1,rightbar:null,rightbarShown:!1,rightbarTrack:!1,rightbarFullscreen:!1,rightbarFocus:!1,rightbarInstant:!1})),D=(0,P.useRef)(280),O=(0,P.useRef)(!1),[k,ee]=(0,P.useState)(!1),te=(0,P.useCallback)(()=>E(e=>({...e,narrowExpanded:!1})),[]),ne=async e=>{if(!O.current){O.current=!0,ee(!0);try{n.session?.sessionId&&await op.flush(n.session.sessionId),await e(),g(!1),te()}catch(e){throw o(e instanceof Error?e.message:String(e)),e}finally{O.current=!1,ee(!1)}}},A=(0,P.useMemo)(()=>({closeSidebar:te,setViewportWidth(e){E(t=>t.viewportWidth===e?t:{...t,viewportWidth:e,narrowExpanded:t.viewportWidth<1024==e<1024&&t.narrowExpanded})},setSidebar(e){D.current=Math.min(420,Math.max(264,Math.round(e))),E(e=>({...e,sidebar:D.current}))},setRightbar(e){E(t=>({...t,rightbar:Ne(e,300,t.viewportWidth*Ae)}))},focusRightbar(){E(e=>({...e,rightbarFocus:!0}))},collapseRightbar(){E(e=>({...e,rightbarFocus:!1})),x.controller.setExpanded(!1)}}),[te,x.controller]),re=e=>{let t=y.flatMap(t=>{let n=t.definition.workbench?.resolvePanel?.(e);return n?[{...n,pluginId:t.id}]:[]})[0];t?x.openContent(t.kind,t.contentId,t.title,void 0,t.pluginId):x.controller.openContent({kind:`plugin`,contentId:e,title:r(`预览`,`Preview`)}),x.controller.setExpanded(!0),g(!1),E(e=>({...e,narrowExpanded:!1}))},ie=()=>x.controller.setExpanded(!1),j=(0,P.useCallback)(e=>{if(!n.session||n.disabledPlugins.includes(d.files))return;let t=Xt(n.session.cwd,e);x.openContent(`file-preview`,t,t.split(`/`).at(-1),void 0,d.files),E(e=>({...e,narrowExpanded:!1}))},[n.session?.cwd,n.disabledPlugins,x.openContent]);(0,P.useEffect)(()=>{let e=T.viewportWidth<767||x.snapshot.state.mode===`fullscreen`;E(t=>({...t,rightbarShown:x.shown&&!h,rightbarTrack:x.shown&&!h,rightbarFullscreen:e,rightbarFocus:t.rightbarFocus&&x.shown&&!h&&!e}))},[x.shown,x.snapshot.state.mode,T.viewportWidth,h]),(0,P.useEffect)(()=>{E(e=>e.rightbarFocus?{...e,rightbarFocus:!1}:e)},[n.session?.sessionId]);let ae=(0,P.useCallback)((e,t)=>(0,F.jsx)(pJ,{text:e,pathImages:t,labels:{code:{copyLabel:r(`复制`,`Copy`),copiedLabel:r(`已复制`,`Copied`),toolbarLabels:{codeLabel:r(`代码块`,`Code block`),wrapLabel:r(`自动换行`,`Wrap`),unwrapLabel:r(`取消换行`,`Unwrap`)}},footnotes:r(`脚注`,`Footnotes`)}}),[e]),oe=async(...e)=>{let t=n.session?.sessionId;o(``);try{if(t){await op.flush(t);for(let e of y)await e.definition.workbench?.beforeSend?.(t)}if(t!==i.current)throw Error(r(`会话已切换,请在原会话重试`,`Session changed. Retry in the original conversation.`))}catch(e){throw o(e instanceof Error?e.message:String(e)),e}return n.send(...e)},M={session:n.session,locale:e,openPanel:re,closePanel:ie,panelId:S,invokePluginAction:n.invokePluginAction,resolvePluginInteraction:n.resolvePluginInteraction,sendMessage:e=>oe(e,[]),renderMarkdown:ae};u.current={openPanel:re,sendMessage:M.sendMessage,abort:n.stop};let se=(e,t)=>(0,F.jsx)(FZ,{plugins:y,slot:e,props:{...M,turn:t}}),ce=()=>E(e=>e.viewportWidth<1024?{...e,narrowExpanded:!e.narrowExpanded}:{...e,sidebar:e.sidebar===0?D.current:0}),le=e=>e({layoutInfo:T}),ue=e=>e({activePanelId:h?`plugins`:null}),de=e=>e([{id:`plugins`,label:r(`插件`,`Plugins`)}]),pe=(e,t,i)=>e===`sidebar.brand.mark`?(0,F.jsx)(Je,{size:24}):e===`sidebar.brand.name`?(0,F.jsx)(`span`,{children:`pi-webapp`}):e===`sidebar.footer.action`?(0,F.jsx)(iA,{wide:t.wide,hideError:p,getUpdate:n.getUpdate,getRunningVersion:n.getRunningVersion,setUpdateChannel:n.setUpdateChannel,cancelUpdate:n.cancelUpdate,update:n.update}):e===`sidebar.panellist`?(0,F.jsx)(fe,{size:t.size}):e===`sidebar.settings`?(0,F.jsxs)(`div`,{className:`pi-settings-trigger-row pi-settings-trigger-split ${t.wide?``:`pi-settings-trigger-rail`}`,children:[!t.wide&&(0,F.jsx)(cA,{wide:!1}),(0,F.jsxs)(`button`,{className:`pi-settings-sidebar`,"data-wide":t.wide,type:`button`,"aria-label":r(`Pi 设置`,`Pi Settings`),"aria-haspopup":`dialog`,"aria-expanded":p,onClick:()=>m(!0),children:[t.wide?(0,F.jsx)(rt,{size:16}):(0,F.jsx)(nt,{size:18}),t.wide&&(0,F.jsx)(`span`,{children:r(`Pi 设置`,`Pi Settings`)})]}),t.wide&&(0,F.jsx)(cA,{wide:!0})]}):e===`sidebar.workspaces`?(0,F.jsx)(XO,{wide:t.wide,expandSidebar:t.expandSidebar,session:n.session,workspaces:n.workspaces,navigationBusy:k,connected:n.connection===`connected`&&n.session!==null,onAdd:(e,t)=>ne(()=>n.addWorkspace(e,t)),directoryPickerKind:n.directoryPickerKind,pickDirectory:n.pickDirectory,listDirectory:n.listDirectory,createDirectory:n.createDirectory,onRemove:e=>ne(()=>n.removeWorkspace(e)),onSelectSession:(e,t,r)=>ne(()=>n.selectSession(e,t,r)),onNewSession:e=>ne(()=>n.newSessionInWorkspace(e)),onRenameSession:(e,t,r,i)=>n.renameSession(e,t,r,i),onDeleteSession:(e,t,r)=>ne(()=>n.deleteSession(e,t,r))}):i?.fallback??null;return(0,F.jsxs)(Tk,{actions:n,children:[f.controllers,(0,F.jsx)(Wt,{closeLabel:r(`关闭`,`Dismiss`),detailLabel:r(`诊断信息`,`Diagnostics`)}),(0,F.jsx)(IQ,{approvals:f.approvals,locale:e,decide:f.decide}),(0,F.jsx)(Ke,{useStore:le,usePanelInfo:ue,actions:A,renderSlot:(r,i)=>r===`sidebar`?(0,F.jsx)(Yt,{collapsed:i.collapsed,width:i.width,startSession:()=>{ne(n.newSession).catch(()=>{})},sessionBusy:k||n.connection!==`connected`||n.session===null,toggleSidebar:ce,selectPanel:()=>{g(!0),te()},usePanels:de,usePanelInfo:ue,t:e=>t[e]??e,renderSlot:pe}):r===`main`?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`div`,{hidden:h,style:{height:`100%`},children:(0,F.jsx)(Qd,{openFile:j,children:(0,F.jsx)(wO,{rightbarControl:(0,F.jsx)(RZ,{panel:x,locale:e}),session:n.session,streaming:n.streaming,connection:n.connection,error:a||n.error,onDismissError:()=>{o(``),n.clearError()},onSend:oe,onUpdateQueuedPrompt:n.updateQueuedPrompt,onLoadImage:n.loadMessageImage,onUpload:n.upload,onDiscardAttachment:n.discardAttachment,onStop:n.stop,onResume:n.resume,onCompact:n.compact,onNewSession:()=>ne(n.newSession),commands:n.commands,models:n.models,modelsStatus:n.modelsStatus,onConfigureModels:()=>m(!0),onSetModel:n.setModel,onSetThinkingLevel:n.setThinkingLevel,composerInteraction:n.session?.interactions?.some(e=>y.some(t=>t.id===e.pluginId&&t.definition.interactions?.some(t=>t.kind===e.kind)))?(0,F.jsx)(NZ,{plugins:y,props:M}):void 0,renderToolView:(e,t,n)=>(0,F.jsx)(PZ,{plugins:y,props:M,call:e,result:t,running:n}),renderPluginSlot:se,plugins:y,onPluginAction:n.invokePluginAction})})}),h&&(0,F.jsx)(nA,{recovery:f.recovery,getPluginManagement:n.getPluginManagement,togglePlugin:n.togglePlugin,generation:n.pluginGeneration})]}):r===`rightbar`&&Object.keys(x.snapshot.state.tabs).length>0?(0,F.jsx)(`div`,{hidden:h,style:{height:`100%`},children:(0,F.jsx)(LZ,{panel:x,cwd:n.session?.cwd,width:i.width,narrow:T.viewportWidth<767,focus:T.rightbarFocus,onExitFocus:()=>E(e=>({...e,rightbarFocus:!1})),plugins:y,props:M},n.session?.sessionId)}):null,t:e=>t[e]??e}),c.length>0&&(0,F.jsxs)(`div`,{className:`pi-plugin-errors`,role:`status`,title:c.join(`
|
|
502
502
|
`),children:[r(`插件加载失败`,`Plugin load failed`),`: `,c.length]}),p&&(0,F.jsx)(Hk,{onBack:w,setupMode:C,getConfig:n.getConfig,updateConfig:n.updateConfig,getUpdate:n.getUpdate,getRunningVersion:n.getRunningVersion,setUpdateChannel:n.setUpdateChannel,cancelUpdate:n.cancelUpdate,update:n.update,getProviders:n.getProviders,getProviderModels:n.getProviderModels,updateProviderModel:n.updateProviderModel,logoutProvider:n.logoutProvider,addCustomProvider:n.addCustomProvider,startProviderLogin:n.startProviderLogin,getProviderLogin:n.getProviderLogin,getActiveProviderLogin:n.getActiveProviderLogin,respondProviderLogin:n.respondProviderLogin,cancelProviderLogin:n.cancelProviderLogin,refreshModels:n.refreshModels})]})}var VQ=e({});fk(),h();var HQ=document.getElementById(`root`);if(!HQ)throw Error(`Missing #root`);(0,De.createRoot)(HQ).render((0,F.jsx)(Oe,{children:(0,F.jsx)(BQ,{})}));export{cB as a,tf as c,TX as i,bZ as n,Np as o,OX as r,kp as s,VQ as t};
|
|
503
|
-
//# debugId=
|
|
503
|
+
//# debugId=91684640-d0ce-4379-99ba-b15e3717e7f1
|