@jonathanleelx/meddle 0.5.0 → 0.5.1
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/bin/commands/mock/add.js +22 -0
- package/bin/commands/mock/index.js +51 -21
- package/bin/commands/route/add.js +2 -2
- package/bin/commands/route/delete.js +2 -2
- package/bin/commands/route/index.js +60 -30
- package/bin/commands/route/preview.js +2 -2
- package/bin/commands/route/show.js +2 -2
- package/bin/commands/route/update.js +2 -2
- package/bin/commands/status.js +27 -11
- package/bin/doctor.js +8 -4
- package/bin/index.js +4 -4
- package/bin/lib/file-access.js +28 -11
- package/bin/lib/meddle-home.js +14 -1
- package/bin/lib/output.js +8 -3
- package/bin/lib/proxy-or-file.js +4 -1
- package/dist/cert.d.ts +2 -0
- package/dist/cert.d.ts.map +1 -1
- package/dist/cert.js +10 -1
- package/dist/cert.js.map +1 -1
- package/dist/core/browser.d.ts +2 -0
- package/dist/core/browser.d.ts.map +1 -1
- package/dist/core/browser.js +21 -8
- package/dist/core/browser.js.map +1 -1
- package/dist/core/mock-handler.d.ts +5 -1
- package/dist/core/mock-handler.d.ts.map +1 -1
- package/dist/core/mock-handler.js +17 -3
- package/dist/core/mock-handler.js.map +1 -1
- package/dist/core/proxy-record.d.ts +14 -0
- package/dist/core/proxy-record.d.ts.map +1 -1
- package/dist/core/proxy-record.js +39 -0
- package/dist/core/proxy-record.js.map +1 -1
- package/dist/core/types.d.ts +2 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/server/config.d.ts.map +1 -1
- package/dist/server/config.js +15 -9
- package/dist/server/config.js.map +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +7 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/json-parse-error.d.ts +7 -0
- package/dist/server/json-parse-error.d.ts.map +1 -0
- package/dist/server/json-parse-error.js +28 -0
- package/dist/server/json-parse-error.js.map +1 -0
- package/dist/server/mocks.d.ts +1 -1
- package/dist/server/mocks.d.ts.map +1 -1
- package/dist/server/rule-files.d.ts.map +1 -1
- package/dist/server/rule-files.js +2 -9
- package/dist/server/rule-files.js.map +1 -1
- package/index.js +92 -9
- package/mcp-server.js +18 -5
- package/package.json +1 -1
- package/web/dist/assets/detail-panel-DZRKJG2W.js +4 -0
- package/web/dist/assets/global-panel-shell-Iir-c_pQ.js +6 -0
- package/web/dist/assets/{health-panel-DhXLqcOU.js → health-panel-Dmf-EhJz.js} +1 -1
- package/web/dist/assets/{index-B-6nUrqW.js → index-C4dIj1nT.js} +5 -5
- package/web/dist/assets/index-CdYMl1M7.css +2 -0
- package/web/dist/assets/{mobile-proxy-panel-BY8Oi-qC.js → mobile-proxy-panel-CFcwa11A.js} +5 -5
- package/web/dist/assets/{mock-config-TPmfJwAt.js → mock-config-CGl50MIr.js} +1 -1
- package/web/dist/assets/mock-editor-panel-xcCk23oH.js +20 -0
- package/web/dist/assets/{mocks-file-missing-note-BR5oWFLh.js → mocks-file-missing-note-CW_ONVLA.js} +1 -1
- package/web/dist/assets/{monaco-editor-BGLPrb0C.js → monaco-editor-BkP7envQ.js} +1 -1
- package/web/dist/assets/{pane-bar-gFRISZLD.js → pane-bar-5j9Nf7W_.js} +1 -1
- package/web/dist/assets/{pane-split-B6aLmY7G.js → pane-split-C0OSe365.js} +1 -1
- package/web/dist/assets/panel-heading-izT5q0ZN.js +1 -0
- package/web/dist/assets/plugin-code-editor-DKE9dFEE.js +2 -0
- package/web/dist/assets/plugin-config-Cg09TsuV.js +2 -0
- package/web/dist/assets/{plugin-generator-Bj4f6dxo.js → plugin-generator-CT1f1tu0.js} +2 -2
- package/web/dist/assets/plugin-test-dialog-BbLIMnkJ.js +7 -0
- package/web/dist/assets/route-preview-CKO7nF4W.js +1 -0
- package/web/dist/assets/{rule-ai-assistant-panel-BEfPNBbx.js → rule-ai-assistant-panel-CtfUqdYG.js} +2 -2
- package/web/dist/assets/rule-config-Cb4ejIXI.js +15 -0
- package/web/dist/assets/rule-overview-panel-xtHTS27O.js +1 -0
- package/web/dist/assets/settings-panel-CpQuE6nr.js +1 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/detail-panel-BtgWWeu3.js +0 -4
- package/web/dist/assets/global-panel-shell-NaUhzX7J.js +0 -6
- package/web/dist/assets/index-EWNlAdFB.css +0 -2
- package/web/dist/assets/mock-editor-panel-WQwcHSTD.js +0 -20
- package/web/dist/assets/panel-heading-DT_nXayM.js +0 -1
- package/web/dist/assets/plugin-code-editor--Gf4ZwGb.js +0 -2
- package/web/dist/assets/plugin-config-DsX9xCW_.js +0 -2
- package/web/dist/assets/plugin-test-dialog-DICuykBK.js +0 -7
- package/web/dist/assets/route-preview-C-LzS1lT.js +0 -1
- package/web/dist/assets/rule-config-Dw9pcuah.js +0 -15
- package/web/dist/assets/rule-overview-panel-C4QQ7U3S.js +0 -1
- package/web/dist/assets/settings-panel-D8DEH8aH.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/global-panel-shell-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/global-panel-shell-Iir-c_pQ.js","assets/button-BFNlGZ5p.js","assets/dist-CFZ4xMSF.js","assets/dist-DLQKRjuW.js","assets/es2015-DPJTBYa9.js","assets/dist-C-E2R2jk.js","assets/dist-CRmX_NvH.js","assets/circle-alert-zMagrFuI.js","assets/ai-config-store-C8D_PUGV.js","assets/rule-config-Cb4ejIXI.js","assets/dist-BQN0rzUS.js","assets/dist-fzPL-8F9.js","assets/checkbox-CQyFsZzS.js","assets/check-BkfHQ6re.js","assets/plus-ixZQRprm.js","assets/table-2-DvGHhMm4.js","assets/toast-9yeTf7d9.js","assets/pane-bar-5j9Nf7W_.js","assets/pane-split-C0OSe365.js","assets/table-DaXD6jJv.js","assets/syntax-highlight-BFgN_C0Y.js","assets/rule-config-CHpVij2M.css","assets/mock-config-CGl50MIr.js","assets/monaco-editor-BkP7envQ.js","assets/code-DD-AYxxu.js","assets/editor-pane-actions-_ckwcCII.js","assets/mock-editor-panel-xcCk23oH.js","assets/wand-sparkles-Bmt4dDOf.js","assets/use-mocks-file-status-BUIUJ4oQ.js","assets/mocks-file-missing-note-CW_ONVLA.js","assets/plugin-config-Cg09TsuV.js","assets/switch-94vgsMHm.js","assets/refresh-cw-BfLoHqg5.js","assets/zap-BuOtogAv.js","assets/detail-panel-DZRKJG2W.js","assets/body-diff-view-SfLCLzs9.js","assets/arrow-right-BNum_060.js","assets/chevron-down-DHwUtL4O.js","assets/circle-x-BEkinhez.js","assets/server-eYXq3PbE.js","assets/copy-BRnscYy1.js","assets/shield-check-hQXjdfZ7.js","assets/clipboard-Bt1qY01V.js","assets/settings-panel-CpQuE6nr.js","assets/rotate-ccw-CRguJya4.js","assets/smartphone-D4Q7cQfm.js","assets/alert-B514Frte.js","assets/plugin-generator-CT1f1tu0.js","assets/panel-heading-izT5q0ZN.js","assets/textarea-9wB8Hsz-.js","assets/plugin-code-editor-DKE9dFEE.js","assets/pencil-line-CEZ7D-de.js","assets/plugin-test-dialog-BbLIMnkJ.js","assets/rule-ai-assistant-panel-CtfUqdYG.js","assets/route-preview-CKO7nF4W.js","assets/rule-overview-panel-xtHTS27O.js","assets/mobile-proxy-panel-CFcwa11A.js","assets/wifi-Cjj_Br1u.js","assets/health-panel-Dmf-EhJz.js"])))=>i.map(i=>d[i]);
|
|
2
2
|
import{a as e,c as t,d as n,f as r,i,l as a,n as o,o as s,p as c,r as l,s as u,t as d,u as f}from"./button-BFNlGZ5p.js";import{a as p,c as m,n as h,o as g,r as _,t as v}from"./dist-CFZ4xMSF.js";import{t as y}from"./check-BkfHQ6re.js";import{t as b}from"./chevron-down-DHwUtL4O.js";import{a as x,c as S,i as C,n as ee,o as te,r as ne,s as w,t as re}from"./dist-BQN0rzUS.js";import{a as ie,c as ae,i as oe,n as se,o as ce,r as le,s as T,t as E}from"./dist-DLQKRjuW.js";import{n as ue,t as de}from"./dist-LiAcI8CK.js";import{t as fe}from"./dist-CRmX_NvH.js";import{n as pe,t as D}from"./dist-C-E2R2jk.js";import{a as O,i as me,n as he,o as ge,r as _e,t as ve}from"./es2015-DPJTBYa9.js";import{n as ye}from"./dist-fzPL-8F9.js";import{n as be,r as xe,t as Se}from"./dist-wv9ebJK_.js";import{t as Ce}from"./dist-Bsv9ad5F.js";import{c as we,o as Te,r as Ee}from"./ai-config-store-C8D_PUGV.js";import{n as De,r as Oe,t as ke}from"./toast-9yeTf7d9.js";import{t as Ae}from"./use-mocks-file-status-BUIUJ4oQ.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var je=r((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,re());else{var t=n(l);t!==null&&oe(x,t.startTime-e)}}var S=!1,C=-1,ee=5,te=-1;function ne(){return g?!0:!(e.unstable_now()-te<ee)}function w(){if(g=!1,S){var t=e.unstable_now();te=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&&ne());){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&&oe(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?re():S=!1}}}var re;if(typeof y==`function`)re=function(){y(w)};else if(typeof MessageChannel<`u`){var ie=new MessageChannel,ae=ie.port2;ie.port1.onmessage=w,re=function(){ae.postMessage(null)}}else re=function(){_(w,0)};function oe(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`):ee=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,oe(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,re()))),r},e.unstable_shouldYield=ne,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),Me=r(((e,t)=>{t.exports=je()})),Ne=r((e=>{var t=Me(),r=n(),i=m();function a(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function o(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function s(e){var t=e,n=e;if(e.alternate)for(;t.return;)t=t.return;else{e=t;do t=e,t.flags&4098&&(n=t.return),e=t.return;while(e)}return t.tag===3?n:null}function 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(a(188))}function d(e){var t=e.alternate;if(!t){if(t=s(e),t===null)throw Error(a(188));return t===e?e:null}for(var n=e,r=t;;){var i=n.return;if(i===null)break;var o=i.alternate;if(o===null){if(r=i.return,r!==null){n=r;continue}break}if(i.child===o.child){for(o=i.child;o;){if(o===n)return u(i),e;if(o===r)return u(i),t;o=o.sibling}throw Error(a(188))}if(n.return!==r.return)n=i,r=o;else{for(var c=!1,l=i.child;l;){if(l===n){c=!0,n=i,r=o;break}if(l===r){c=!0,r=i,n=o;break}l=l.sibling}if(!c){for(l=o.child;l;){if(l===n){c=!0,n=o,r=i;break}if(l===r){c=!0,r=o,n=i;break}l=l.sibling}if(!c)throw Error(a(189))}}if(n.alternate!==r)throw Error(a(190))}if(n.tag!==3)throw Error(a(188));return n.stateNode.current===n?e:t}function 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}var p=Object.assign,h=Symbol.for(`react.element`),g=Symbol.for(`react.transitional.element`),_=Symbol.for(`react.portal`),v=Symbol.for(`react.fragment`),y=Symbol.for(`react.strict_mode`),b=Symbol.for(`react.profiler`),x=Symbol.for(`react.consumer`),S=Symbol.for(`react.context`),C=Symbol.for(`react.forward_ref`),ee=Symbol.for(`react.suspense`),te=Symbol.for(`react.suspense_list`),ne=Symbol.for(`react.memo`),w=Symbol.for(`react.lazy`),re=Symbol.for(`react.activity`),ie=Symbol.for(`react.memo_cache_sentinel`),ae=Symbol.iterator;function oe(e){return typeof e!=`object`||!e?null:(e=ae&&e[ae]||e[`@@iterator`],typeof e==`function`?e:null)}var se=Symbol.for(`react.client.reference`);function ce(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===se?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case v:return`Fragment`;case b:return`Profiler`;case y:return`StrictMode`;case ee:return`Suspense`;case te:return`SuspenseList`;case re:return`Activity`}if(typeof e==`object`)switch(e.$$typeof){case _:return`Portal`;case S:return e.displayName||`Context`;case x:return(e._context.displayName||`Context`)+`.Consumer`;case C:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case ne:return t=e.displayName||null,t===null?ce(e.type)||`Memo`:t;case w:t=e._payload,e=e._init;try{return ce(e(t))}catch{}}return null}var le=Array.isArray,T=r.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,E=i.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,ue={pending:!1,data:null,method:null,action:null},de=[],fe=-1;function pe(e){return{current:e}}function D(e){0>fe||(e.current=de[fe],de[fe]=null,fe--)}function O(e,t){fe++,de[fe]=e.current,e.current=t}var me=pe(null),he=pe(null),ge=pe(null),_e=pe(null);function ve(e,t){switch(O(ge,t),O(he,e),O(me,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?Vd(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=Vd(t),e=Hd(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}D(me),O(me,e)}function ye(){D(me),D(he),D(ge)}function be(e){e.memoizedState!==null&&O(_e,e);var t=me.current,n=Hd(t,e.type);t!==n&&(O(he,e),O(me,n))}function xe(e){he.current===e&&(D(me),D(he)),_e.current===e&&(D(_e),Qf._currentValue=ue)}var Se,Ce;function we(e){if(Se===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);Se=t&&t[1]||``,Ce=-1<e.stack.indexOf(`
|
|
3
3
|
at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
|
|
4
4
|
`+Se+e+Ce}var Te=!1;function Ee(e,t){if(!e||Te)return``;Te=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var r={DetermineComponentFrameRoot:function(){try{if(t){var n=function(){throw Error()};if(Object.defineProperty(n.prototype,`props`,{set:function(){throw Error()}}),typeof Reflect==`object`&&Reflect.construct){try{Reflect.construct(n,[])}catch(e){var r=e}Reflect.construct(e,[],n)}else{try{n.call()}catch(e){r=e}e.call(n.prototype)}}else{try{throw Error()}catch(e){r=e}(n=e())&&typeof n.catch==`function`&&n.catch(function(){})}}catch(e){if(e&&r&&typeof e.stack==`string`)return[e.stack,r.stack]}return[null,null]}};r.DetermineComponentFrameRoot.displayName=`DetermineComponentFrameRoot`;var i=Object.getOwnPropertyDescriptor(r.DetermineComponentFrameRoot,`name`);i&&i.configurable&&Object.defineProperty(r.DetermineComponentFrameRoot,`name`,{value:`DetermineComponentFrameRoot`});var a=r.DetermineComponentFrameRoot(),o=a[0],s=a[1];if(o&&s){var c=o.split(`
|
|
@@ -13,9 +13,9 @@ Please change the parent <Route path="${e}"> to <Route path="${e===`/`?`*`:`${e}
|
|
|
13
13
|
font-size: .6rem;
|
|
14
14
|
font-weight: bold;
|
|
15
15
|
color: hsl(${Math.max(0,Math.min(120-120*r,120))}deg 100% 31%);`,n?.key)}return n?.onChange&&!(a&&n.skipInitialOnChange)&&n.onChange(i),a=!1,i}return o.updateDeps=e=>{r=e},o}function Oc(e,t){if(e===void 0)throw Error(`Unexpected undefined${t?`: ${t}`:``}`);return e}var kc=(e,t)=>Math.abs(e-t)<1.01,Ac=(e,t,n)=>{let r;return function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)}},jc=e=>{let{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},Mc=e=>e,Nc=e=>{let t=Math.max(e.startIndex-e.overscan,0),n=Math.min(e.endIndex+e.overscan,e.count-1),r=[];for(let e=t;e<=n;e++)r.push(e);return r},Pc=(e,t)=>{let n=e.scrollElement;if(!n)return;let r=e.targetWindow;if(!r)return;let i=e=>{let{width:n,height:r}=e;t({width:Math.round(n),height:Math.round(r)})};if(i(jc(n)),!r.ResizeObserver)return()=>{};let a=new r.ResizeObserver(t=>{let r=()=>{let e=t[0];if(e?.borderBoxSize){let t=e.borderBoxSize[0];if(t){i({width:t.inlineSize,height:t.blockSize});return}}i(jc(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(r):r()});return a.observe(n,{box:`border-box`}),()=>{a.unobserve(n)}},Fc={passive:!0},Ic=typeof window>`u`?!0:`onscrollend`in window,Lc=(e,t)=>{let n=e.scrollElement;if(!n)return;let r=e.targetWindow;if(!r)return;let i=0,a=e.options.useScrollendEvent&&Ic?()=>void 0:Ac(r,()=>{t(i,!1)},e.options.isScrollingResetDelay),o=r=>()=>{let{horizontal:o,isRtl:s}=e.options;i=o?n.scrollLeft*(s&&-1||1):n.scrollTop,a(),t(i,r)},s=o(!0),c=o(!1);n.addEventListener(`scroll`,s,Fc);let l=e.options.useScrollendEvent&&Ic;return l&&n.addEventListener(`scrollend`,c,Fc),()=>{n.removeEventListener(`scroll`,s),l&&n.removeEventListener(`scrollend`,c)}},Rc=(e,t,n)=>{if(t?.borderBoxSize){let e=t.borderBoxSize[0];if(e)return Math.round(e[n.options.horizontal?`inlineSize`:`blockSize`])}return e[n.options.horizontal?`offsetWidth`:`offsetHeight`]},zc=(e,{adjustments:t=0,behavior:n},r)=>{var i,a;let o=e+t;(a=(i=r.scrollElement)?.scrollTo)==null||a.call(i,{[r.options.horizontal?`left`:`top`]:o,behavior:n})},Bc=class{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.currentScrollToIndex=null,this.measurementsCache=[],this.itemSizeCache=new Map,this.laneAssignments=new Map,this.pendingMeasuredCacheIndexes=[],this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this.elementsCache=new Map,this.observer=(()=>{let e=null,t=()=>e||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:e=new this.targetWindow.ResizeObserver(e=>{e.forEach(e=>{let t=()=>{this._measureElement(e.target,e)};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(t):t()})}));return{disconnect:()=>{var n;(n=t())==null||n.disconnect(),e=null},observe:e=>t()?.observe(e,{box:`border-box`}),unobserve:e=>t()?.unobserve(e)}})(),this.range=null,this.setOptions=e=>{Object.entries(e).forEach(([t,n])=>{n===void 0&&delete e[t]}),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:Mc,rangeExtractor:Nc,onChange:()=>{},measureElement:Rc,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:`data-index`,initialMeasurementsCache:[],lanes:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,...e}},this.notify=e=>{var t,n;(n=(t=this.options).onChange)==null||n.call(t,this,e)},this.maybeNotify=Dc(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),e=>{this.notify(e)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(e=>e()),this.unsubs=[],this.observer.disconnect(),this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{let e=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==e){if(this.cleanup(),!e){this.maybeNotify();return}this.scrollElement=e,this.scrollElement&&`ownerDocument`in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=this.scrollElement?.window??null,this.elementsCache.forEach(e=>{this.observer.observe(e)}),this.unsubs.push(this.options.observeElementRect(this,e=>{this.scrollRect=e,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(e,t)=>{this.scrollAdjustments=0,this.scrollDirection=t?this.getScrollOffset()<e?`forward`:`backward`:null,this.scrollOffset=e,this.isScrolling=t,this.maybeNotify()})),this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}},this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?`width`:`height`]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset==`function`?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(e,t)=>{let n=new Map,r=new Map;for(let i=t-1;i>=0;i--){let t=e[i];if(n.has(t.lane))continue;let a=r.get(t.lane);if(a==null||t.end>a.end?r.set(t.lane,t):t.end<a.end&&n.set(t.lane,!0),n.size===this.options.lanes)break}return r.size===this.options.lanes?Array.from(r.values()).sort((e,t)=>e.end===t.end?e.index-t.index:e.end-t.end)[0]:void 0},this.getMeasurementOptions=Dc(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes],(e,t,n,r,i,a)=>(this.prevLanes!==void 0&&this.prevLanes!==a&&(this.lanesChangedFlag=!0),this.prevLanes=a,this.pendingMeasuredCacheIndexes=[],{count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a}),{key:!1}),this.getMeasurements=Dc(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a},o)=>{if(!i)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>e)for(let t of this.laneAssignments.keys())t>=e&&this.laneAssignments.delete(t);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMeasuredCacheIndexes=[]),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(e=>{this.itemSizeCache.set(e.key,e.size)}));let s=this.lanesSettling?0:this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[],this.lanesSettling&&this.measurementsCache.length===e&&(this.lanesSettling=!1);let c=this.measurementsCache.slice(0,s),l=Array(a).fill(void 0);for(let e=0;e<s;e++){let t=c[e];t&&(l[t.lane]=e)}for(let i=s;i<e;i++){let e=r(i),a=this.laneAssignments.get(i),s,u;if(a!==void 0&&this.options.lanes>1){s=a;let e=l[s],r=e===void 0?void 0:c[e];u=r?r.end+this.options.gap:t+n}else{let e=this.options.lanes===1?c[i-1]:this.getFurthestMeasurement(c,i);u=e?e.end+this.options.gap:t+n,s=e?e.lane:i%this.options.lanes,this.options.lanes>1&&this.laneAssignments.set(i,s)}let d=o.get(e),f=typeof d==`number`?d:this.options.estimateSize(i),p=u+f;c[i]={index:i,start:u,size:f,end:p,key:e,lane:s},l[s]=i}return this.measurementsCache=c,c},{key:!1,debug:()=>this.options.debug}),this.calculateRange=Dc(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(e,t,n,r)=>this.range=e.length>0&&t>0?Vc({measurements:e,outerSize:t,scrollOffset:n,lanes:r}):null,{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=Dc(()=>{let e=null,t=null,n=this.calculateRange();return n&&(e=n.startIndex,t=n.endIndex),this.maybeNotify.updateDeps([this.isScrolling,e,t]),[this.options.rangeExtractor,this.options.overscan,this.options.count,e,t]},(e,t,n,r,i)=>r===null||i===null?[]:e({startIndex:r,endIndex:i,overscan:t,count:n}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=e=>{let t=this.options.indexAttribute,n=e.getAttribute(t);return n?parseInt(n,10):(console.warn(`Missing attribute name '${t}={index}' on measured element.`),-1)},this._measureElement=(e,t)=>{let n=this.indexFromElement(e),r=this.measurementsCache[n];if(!r)return;let i=r.key,a=this.elementsCache.get(i);a!==e&&(a&&this.observer.unobserve(a),this.observer.observe(e),this.elementsCache.set(i,e)),e.isConnected&&this.resizeItem(n,this.options.measureElement(e,t,this))},this.resizeItem=(e,t)=>{let n=this.measurementsCache[e];if(!n)return;let r=t-(this.itemSizeCache.get(n.key)??n.size);r!==0&&((this.shouldAdjustScrollPositionOnItemSizeChange===void 0?n.start<this.getScrollOffset()+this.scrollAdjustments:this.shouldAdjustScrollPositionOnItemSizeChange(n,r,this))&&this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=r,behavior:void 0}),this.pendingMeasuredCacheIndexes.push(n.index),this.itemSizeCache=new Map(this.itemSizeCache.set(n.key,t)),this.notify(!1))},this.measureElement=e=>{if(!e){this.elementsCache.forEach((e,t)=>{e.isConnected||(this.observer.unobserve(e),this.elementsCache.delete(t))});return}this._measureElement(e,void 0)},this.getVirtualItems=Dc(()=>[this.getVirtualIndexes(),this.getMeasurements()],(e,t)=>{let n=[];for(let r=0,i=e.length;r<i;r++){let i=t[e[r]];n.push(i)}return n},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=e=>{let t=this.getMeasurements();if(t.length!==0)return Oc(t[V(0,t.length-1,e=>Oc(t[e]).start,e)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if(`scrollHeight`in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{let e=this.scrollElement.document.documentElement;return this.options.horizontal?e.scrollWidth-this.scrollElement.innerWidth:e.scrollHeight-this.scrollElement.innerHeight}},this.getOffsetForAlignment=(e,t,n=0)=>{if(!this.scrollElement)return 0;let r=this.getSize(),i=this.getScrollOffset();t===`auto`&&(t=e>=i+r?`end`:`start`),t===`center`?e+=(n-r)/2:t===`end`&&(e-=r);let a=this.getMaxScrollOffset();return Math.max(Math.min(a,e),0)},this.getOffsetForIndex=(e,t=`auto`)=>{e=Math.max(0,Math.min(e,this.options.count-1));let n=this.measurementsCache[e];if(!n)return;let r=this.getSize(),i=this.getScrollOffset();if(t===`auto`)if(n.end>=i+r-this.options.scrollPaddingEnd)t=`end`;else if(n.start<=i+this.options.scrollPaddingStart)t=`start`;else return[i,t];if(t===`end`&&e===this.options.count-1)return[this.getMaxScrollOffset(),t];let a=t===`end`?n.end+this.options.scrollPaddingEnd:n.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(a,t,n.size),t]},this.isDynamicMode=()=>this.elementsCache.size>0,this.scrollToOffset=(e,{align:t=`start`,behavior:n}={})=>{n===`smooth`&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),this._scrollToOffset(this.getOffsetForAlignment(e,t),{adjustments:void 0,behavior:n})},this.scrollToIndex=(e,{align:t=`auto`,behavior:n}={})=>{n===`smooth`&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),e=Math.max(0,Math.min(e,this.options.count-1)),this.currentScrollToIndex=e;let r=0,i=t=>{if(!this.targetWindow)return;let r=this.getOffsetForIndex(e,t);if(!r){console.warn(`Failed to get offset for index:`,e);return}let[i,o]=r;this._scrollToOffset(i,{adjustments:void 0,behavior:n}),this.targetWindow.requestAnimationFrame(()=>{let t=()=>{if(this.currentScrollToIndex!==e)return;let t=this.getScrollOffset(),n=this.getOffsetForIndex(e,o);if(!n){console.warn(`Failed to get offset for index:`,e);return}kc(n[0],t)||a(o)};this.isDynamicMode()?this.targetWindow.requestAnimationFrame(t):t()})},a=t=>{this.targetWindow&&this.currentScrollToIndex===e&&(r++,r<10?this.targetWindow.requestAnimationFrame(()=>i(t)):console.warn(`Failed to scroll to index ${e} after 10 attempts.`))};i(t)},this.scrollBy=(e,{behavior:t}={})=>{t===`smooth`&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),this._scrollToOffset(this.getScrollOffset()+e,{adjustments:void 0,behavior:t})},this.getTotalSize=()=>{let e=this.getMeasurements(),t;if(e.length===0)t=this.options.paddingStart;else if(this.options.lanes===1)t=e[e.length-1]?.end??0;else{let n=Array(this.options.lanes).fill(null),r=e.length-1;for(;r>=0&&n.some(e=>e===null);){let t=e[r];n[t.lane]===null&&(n[t.lane]=t.end),r--}t=Math.max(...n.filter(e=>e!==null))}return Math.max(t-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(e,{adjustments:t,behavior:n})=>{this.options.scrollToFn(e,{behavior:n,adjustments:t},this)},this.measure=()=>{this.itemSizeCache=new Map,this.laneAssignments=new Map,this.notify(!1)},this.setOptions(e)}},V=(e,t,n,r)=>{for(;e<=t;){let i=(e+t)/2|0,a=n(i);if(a<r)e=i+1;else if(a>r)t=i-1;else return i}return e>0?e-1:0};function Vc({measurements:e,outerSize:t,scrollOffset:n,lanes:r}){let i=e.length-1,a=t=>e[t].start;if(e.length<=r)return{startIndex:0,endIndex:i};let o=V(0,i,a,n),s=o;if(r===1)for(;s<i&&e[s].end<n+t;)s++;else if(r>1){let a=Array(r).fill(0);for(;s<i&&a.some(e=>e<n+t);){let t=e[s];a[t.lane]=t.end,s++}let c=Array(r).fill(n+t);for(;o>=0&&c.some(e=>e>=n);){let t=e[o];c[t.lane]=t.start,o--}o=Math.max(0,o-o%r),s=Math.min(i,s+(r-1-s%r))}return{startIndex:o,endIndex:s}}var Hc=typeof document<`u`?k.useLayoutEffect:k.useEffect;function Uc({useFlushSync:e=!0,...t}){let n=k.useReducer(()=>({}),{})[1],r={...t,onChange:(r,i)=>{var a;e&&i?(0,Fe.flushSync)(n):n(),(a=t.onChange)==null||a.call(t,r,i)}},[i]=k.useState(()=>new Bc(r));return i.setOptions(r),Hc(()=>i._didMount(),[]),Hc(()=>i._willUpdate()),i}function Wc(e){return Uc({observeElementRect:Pc,observeElementOffset:Lc,scrollToFn:zc,...e})}function Gc({className:e,...t}){return(0,N.jsx)(`div`,{"data-slot":`empty`,className:a(`flex min-w-0 flex-1 flex-col items-center justify-center gap-6 rounded-lg border-dashed p-6 text-center text-balance md:p-12`,e),...t})}function Kc({className:e,...t}){return(0,N.jsx)(`div`,{"data-slot":`empty-header`,className:a(`flex max-w-sm flex-col items-center gap-2 text-center`,e),...t})}var qc=u(`mb-2 flex shrink-0 items-center justify-center [&_svg]:pointer-events-none [&_svg]:shrink-0`,{variants:{variant:{default:`bg-transparent`,icon:`flex size-10 shrink-0 items-center justify-center rounded-lg bg-muted text-foreground [&_svg:not([class*='size-'])]:size-6`}},defaultVariants:{variant:`default`}});function Jc({className:e,variant:t=`default`,...n}){return(0,N.jsx)(`div`,{"data-slot":`empty-icon`,"data-variant":t,className:a(qc({variant:t,className:e})),...n})}function Yc({className:e,...t}){return(0,N.jsx)(`div`,{"data-slot":`empty-title`,className:a(`text-lg font-medium tracking-tight`,e),...t})}function Xc({className:e,...t}){return(0,N.jsx)(`div`,{"data-slot":`empty-description`,className:a(`text-sm/relaxed text-muted-foreground [&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-primary`,e),...t})}function Zc({className:e,...t}){return(0,N.jsx)(`div`,{"data-slot":`empty-content`,className:a(`flex w-full max-w-sm min-w-0 flex-col items-center gap-4 text-sm text-balance`,e),...t})}function Qc({className:e,children:t,viewportProps:n,...r}){return(0,N.jsxs)(da,{"data-slot":`scroll-area`,className:a(`relative`,e),...r,children:[(0,N.jsx)(fa,{...n,"data-slot":`scroll-area-viewport`,className:`focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1`,children:t}),(0,N.jsx)($c,{}),(0,N.jsx)(pa,{})]})}function $c({className:e,orientation:t=`vertical`,...n}){return(0,N.jsx)(Bi,{"data-slot":`scroll-area-scrollbar`,orientation:t,className:a(`flex touch-none transition-colors select-none`,t===`vertical`&&`h-full w-1.5 border-l border-l-transparent`,t===`horizontal`&&`h-1.5 flex-col border-t border-t-transparent`,e),...n,children:(0,N.jsx)(Zi,{"data-slot":`scroll-area-thumb`,className:`relative flex-1 rounded-full bg-foreground/20 hover:bg-foreground/35`})})}function el(e){let t=`${e.applicationName||``} ${e.applicationProcess||``}`.toLowerCase();return t.includes(`chrome`)||t.includes(`chromium`)?{icon:Fr,name:`chrome`,className:`bg-blue-500/12 text-blue-600 dark:text-blue-400`}:t.includes(`safari`)?{icon:Br,name:`safari`,className:`bg-sky-500/12 text-sky-600 dark:text-sky-400`}:t.includes(`edge`)?{icon:ri,name:`edge`,className:`bg-teal-500/12 text-teal-600 dark:text-teal-400`}:t.includes(`firefox`)?{icon:Gr,name:`firefox`,className:`bg-orange-500/12 text-orange-600 dark:text-orange-400`}:t.includes(`opera`)?{icon:Lr,name:`opera`,className:`bg-red-500/12 text-red-600 dark:text-red-400`}:t.includes(`duckduckgo`)?{icon:hi,name:`duckduckgo`,className:`bg-orange-500/12 text-orange-600 dark:text-orange-400`}:t.includes(`webview`)?{icon:oi,name:`webview`,className:`bg-violet-500/12 text-violet-600 dark:text-violet-400`}:t.includes(`samsung internet`)?{icon:Vr,name:`samsung-internet`,className:`bg-indigo-500/12 text-indigo-600 dark:text-indigo-400`}:t.includes(`curl`)||t.includes(`wget`)||t.includes(`terminal`)?{icon:bi,name:`terminal`,className:`bg-slate-500/12 text-slate-600 dark:text-slate-300`}:t.includes(`node`)?{icon:Jr,name:`node`,className:`bg-green-500/12 text-green-600 dark:text-green-400`}:e.applicationIdentitySource===`user-agent`?{icon:Vr,name:`browser`,className:`bg-cyan-500/12 text-cyan-600 dark:text-cyan-400`}:{icon:kr,name:`application`,className:`bg-muted text-muted-foreground`}}function tl({record:e,className:t,compact:n=!1}){let r=el(e),i=r.icon;return(0,N.jsx)(`span`,{"aria-hidden":`true`,"data-application-icon":r.name,className:a(`inline-flex shrink-0 items-center justify-center rounded-md`,n?`size-5`:`size-6`,r.className,t),children:(0,N.jsx)(i,{className:n?`size-3.5`:`size-4`,strokeWidth:2})})}function nl(e){return e.mock?{kind:`mock`,badge:`Mock`,title:`命中 Mock`,description:`该请求由本地 Mock 短路返回,未转发到上游。`}:e.source===e.target?{kind:`pass`,badge:`—`,title:`未改写 / 透传`,description:`源与目标一致,未命中 Mock;如有规则则未改写地址。`}:{kind:`rule`,badge:`Rule`,title:`命中 Rule · 转发改写`,description:`源地址与目标地址不同,请求路径被规则改写后转发。`}}var rl=`inline-flex h-[14px] min-w-[28px] items-center justify-center rounded-sm border px-1 text-[9px] leading-none`,il={mock:`border-border bg-muted font-semibold text-foreground`,rule:`border-border bg-muted/70 font-semibold text-foreground`,pass:`border-dashed border-muted-foreground/40 bg-transparent font-normal text-muted-foreground`};function al({record:e,className:t,summary:n}){let r=n??nl(e);return(0,N.jsx)(`span`,{role:`status`,"data-slot":`traffic-hit-badge`,"data-hit-kind":r.kind,title:r.title,className:a(rl,il[r.kind],t),children:r.badge})}var ol=`h-[16px] px-[4px] py-0 font-mono text-[10px] leading-none`,H=`flex h-7 shrink-0 items-center px-1.5 leading-none`,sl=22;function cl(e){switch(e.toUpperCase()){case`POST`:return`default`;case`DELETE`:return`destructive`;case`GET`:return`secondary`;default:return`outline`}}function ll(e){return e>=400?`destructive`:e>=300?`secondary`:e>=200?`default`:`outline`}function U(e){return e<1e3?`${e}ms`:`${(e/1e3).toFixed(1)}s`}function ul(e){return e.clientType===`local`?e.clientName||`本机`:e.clientType===`plugin`?e.clientName||`插件`:e.clientType===`remote`?e.clientName||`远程`:`未标记`}function dl(e){return e.clientType===`plugin`?`default`:e.clientType===`remote`?`secondary`:`outline`}function fl(e){return[e.applicationName,e.applicationIdentitySource===`local-process`?`识别方式: 本机进程`:e.applicationIdentitySource===`user-agent`?`识别方式: User-Agent 推断`:e.applicationIdentitySource===`client-reported`?`识别方式: 客户端上报`:void 0,e.applicationIdentityConfidence?`可信度: ${e.applicationIdentityConfidence===`high`?`高`:e.applicationIdentityConfidence===`medium`?`中`:`低`}`:void 0,e.applicationProcess&&e.applicationProcess!==e.applicationName?`进程: ${e.applicationProcess}`:void 0,e.applicationPid?`PID: ${e.applicationPid}`:void 0,e.applicationBundleId?`Bundle ID: ${e.applicationBundleId}`:void 0,e.applicationPath].filter(Boolean).join(`
|
|
16
|
-
`)}function pl(e){return e.applicationIdentitySource===`user-agent`}function ml({records:e,selectedRecordId:t,onSelect:n,autoScroll:r}){let i=(0,k.useRef)(null),o=(0,k.useRef)(e.length),s=(0,k.useRef)(!0),[c,l]=(0,k.useState)(`desc`),u=Wc({count:e.length,getScrollElement:()=>i.current?.querySelector(`[data-radix-scroll-area-viewport]`),estimateSize:()=>22,overscan:10}),f=u.getVirtualItems();return(0,k.useEffect)(()=>{let e=i.current?.querySelector(`[data-radix-scroll-area-viewport]`);if(!(e instanceof HTMLElement))return;let t=()=>{s.current=c===`desc`?e.scrollTop<=sl:e.scrollHeight-e.scrollTop-e.clientHeight<=sl};return t(),e.addEventListener(`scroll`,t,{passive:!0}),()=>e.removeEventListener(`scroll`,t)},[c]),(0,k.useEffect)(()=>{if(r&&s.current&&e.length>o.current){let e=i.current?.querySelector(`[data-radix-scroll-area-viewport]`);e&&requestAnimationFrame(()=>{e.scrollTop=c===`desc`?0:e.scrollHeight})}o.current=e.length},[e.length,r,c]),(0,N.jsx)(`div`,{className:`meddle-thin-scroll relative flex min-h-0 flex-1 overflow-x-auto`,children:(0,N.jsxs)(`div`,{className:`flex min-h-0 min-w-[960px] flex-1 flex-col`,children:[(0,N.jsxs)(`div`,{className:`z-10 flex h-7 shrink-0 items-stretch border-b bg-muted/70 text-[11px] font-medium backdrop-blur supports-[backdrop-filter]:bg-muted/90`,children:[(0,N.jsx)(`div`,{className:a(H,`w-16`),children:`方法`}),(0,N.jsx)(`div`,{className:a(H,`w-14`),children:`状态`}),(0,N.jsx)(`div`,{className:a(H,`w-24`),children:`来源`}),(0,N.jsx)(`div`,{className:a(H,`w-44`),children:`应用`}),(0,N.jsx)(`div`,{className:a(H,`min-w-[200px] flex-1`),children:`源地址`}),(0,N.jsx)(`div`,{className:a(H,`min-w-[200px] flex-1`),children:`目标地址`}),(0,N.jsx)(`div`,{className:a(H,`w-14`),children:`协议`}),(0,N.jsx)(`div`,{className:a(H,`w-16`),children:`耗时`}),(0,N.jsx)(`div`,{className:a(H,`w-24`),children:(0,N.jsxs)(d,{variant:`ghost`,size:`xs`,onClick:()=>{let e=c===`desc`?`asc`:`desc`;s.current=e===`desc`,l(e),u.scrollToOffset(0)},className:`-ml-1 h-6 px-1.5 text-[11px]`,title:c===`desc`?`倒序(新→旧),点击切换为正序`:`正序(旧→新),点击切换为倒序`,children:[`时间`,c===`desc`?(0,N.jsx)(Ar,{"data-icon":`inline-end`}):(0,N.jsx)(jr,{"data-icon":`inline-end`})]})}),(0,N.jsx)(`div`,{className:a(H,`w-14`),children:`命中`})]}),(0,N.jsx)(Qc,{className:`min-h-0 flex-1`,ref:i,children:(0,N.jsx)(`div`,{className:`min-w-full`,children:e.length===0?(0,N.jsx)(Gc,{className:`min-h-72 border-0`,children:(0,N.jsxs)(Kc,{children:[(0,N.jsx)(Jc,{variant:`icon`,children:(0,N.jsx)(Yr,{})}),(0,N.jsx)(Yc,{children:`暂无请求记录`}),(0,N.jsx)(Xc,{children:`打开需要调试的页面后,请求会实时显示在这里。`})]})}):(0,N.jsx)(`div`,{style:{height:`${u.getTotalSize()}px`,position:`relative`},children:f.map(r=>{let i=e[c===`desc`?r.index:e.length-1-r.index];return(0,N.jsxs)(`div`,{className:a(`absolute flex w-full items-center cursor-pointer border-b border-border/40 text-[11px] transition-colors`,t===i.id?`bg-accent`:`hover:bg-muted/50`),onClick:()=>i.id!=null&&n(i.id),style:{height:`${r.size}px`,transform:`translateY(${r.start}px)`},children:[(0,N.jsx)(`div`,{className:`flex h-full w-16 items-center px-2`,children:(0,N.jsx)(fc,{variant:cl(i.method),className:ol,children:i.method})}),(0,N.jsx)(`div`,{className:`flex h-full w-14 items-center px-2`,children:i.statusCode!=null&&(0,N.jsx)(fc,{variant:ll(i.statusCode),className:ol,children:i.statusCode})}),(0,N.jsx)(`div`,{className:`flex h-full w-24 items-center truncate px-2`,title:[i.clientName,i.clientIp].filter(Boolean).join(` · `)||`未标记来源`,children:(0,N.jsx)(fc,{variant:dl(i),className:a(ol,`max-w-full`),children:(0,N.jsx)(`span`,{className:`truncate`,children:ul(i)})})}),(0,N.jsx)(`div`,{className:`flex h-full w-44 items-center gap-1.5 truncate px-2`,title:fl(i)||(i.clientType===`plugin`?``:`未识别到请求应用`),children:i.applicationName?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(tl,{record:i,compact:!0}),(0,N.jsx)(`span`,{className:`truncate`,children:i.applicationName}),pl(i)&&(0,N.jsx)(`span`,{className:`shrink-0 rounded border px-1 text-[9px] leading-4 text-muted-foreground`,children:`推断`})]}):(0,N.jsx)(`span`,{className:`truncate text-muted-foreground`,children:i.clientType===`plugin`?`—`:`未知应用`})}),(0,N.jsxs)(`div`,{className:`flex h-full min-w-[200px] flex-1 items-center truncate px-2 font-mono`,title:i.source,children:[i._fromPluginTest&&(0,N.jsx)(fc,{variant:`secondary`,className:a(ol,`mr-1`),children:`插件测试`}),i.source]}),(0,N.jsx)(`div`,{className:`flex h-full min-w-[200px] flex-1 items-center truncate px-2 font-mono`,title:i.target,children:i.target}),(0,N.jsx)(`div`,{className:`flex h-full w-14 items-center px-2`,children:i.protocol&&(0,N.jsx)(fc,{variant:i.protocol===`h2`?`secondary`:`outline`,className:ol,children:i.protocol})}),(0,N.jsx)(`div`,{className:`flex h-full w-16 items-center px-2 font-mono text-[10px] text-muted-foreground`,children:i.duration!=null&&U(i.duration)}),(0,N.jsx)(`div`,{className:`flex h-full w-24 items-center px-1.5 font-mono text-[10px] text-muted-foreground`,children:i.time}),(0,N.jsx)(`div`,{className:`flex h-full w-14 items-center px-1.5`,children:(0,N.jsx)(al,{record:i})})]},i.id??r.index)})})})})]})})}var hl=`meddle-traffic-split-pct`;function gl(e){return Number.isFinite(e)?Math.max(35,Math.min(75,Math.round(e))):60}function _l(){if(typeof window>`u`)return 60;try{let e=localStorage.getItem(hl);return e==null?60:gl(parseFloat(e))}catch{return 60}}function vl(e){let t=gl(e);try{localStorage.setItem(hl,String(t))}catch{}return t}function yl(e,t,n){return n<=0?60:gl((e-t)/n*100)}function bl(e){let[t,n]=(0,k.useState)(()=>typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(e).matches);return(0,k.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let t=window.matchMedia(e),r=()=>n(t.matches);return r(),t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t}function xl({master:e,detail:t,drawer:n,detailOpen:r=!0,className:i}){let o=bl(`(max-width: 900px)`),s=(0,k.useRef)(null),[c,l]=(0,k.useState)(_l),[u,d]=(0,k.useState)(!1);(0,k.useEffect)(()=>{if(!u)return;let e=e=>{let t=s.current;if(!t)return;let n=t.getBoundingClientRect();l(yl(e.clientX,n.left,n.width))},t=()=>{d(!1),l(e=>vl(e)),document.body.style.cursor=``,document.body.style.userSelect=``};return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`,()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t),document.body.style.cursor=``,document.body.style.userSelect=``}},[u]);let f=(0,k.useCallback)(e=>{e.preventDefault(),d(!0)},[]);return o?(0,N.jsxs)(`div`,{"data-testid":`traffic-work-layout`,"data-layout":`narrow`,"data-detail-open":r?`true`:`false`,className:a(`flex min-h-0 flex-1 flex-col overflow-hidden`,i),children:[(0,N.jsx)(`div`,{"data-testid":`traffic-master`,className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:e}),n]}):r?(0,N.jsxs)(`div`,{ref:s,"data-testid":`traffic-work-layout`,"data-layout":`split`,"data-detail-open":`true`,"data-split-pct":c,className:a(`flex min-h-0 flex-1 overflow-hidden`,i),children:[(0,N.jsx)(`div`,{"data-testid":`traffic-master`,className:`flex min-h-0 min-w-0 shrink-0 flex-col overflow-hidden`,style:{flex:`0 0 ${c}%`,width:`${c}%`},children:e}),(0,N.jsxs)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-valuenow":c,"aria-valuemin":35,"aria-valuemax":75,"aria-label":`调整流量列表与详情分栏宽度`,"data-testid":`traffic-split-handle`,className:`group relative z-10 w-px shrink-0 cursor-col-resize`,onMouseDown:f,children:[(0,N.jsx)(`div`,{"aria-hidden":!0,className:a(`pointer-events-none absolute inset-0 bg-border transition-colors`,u?`bg-primary`:`group-hover:bg-transparent`)}),(0,N.jsx)(`div`,{"aria-hidden":!0,className:a(`pointer-events-none absolute inset-y-0 left-1/2 w-1 -translate-x-1/2 opacity-0 transition-opacity`,u?`bg-primary opacity-100`:`bg-primary/60 group-hover:opacity-100`)}),(0,N.jsx)(`div`,{className:`absolute inset-y-0 -left-1.5 -right-1.5`})]}),(0,N.jsx)(`div`,{"data-testid":`traffic-detail`,className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:t})]}):(0,N.jsx)(`div`,{"data-testid":`traffic-work-layout`,"data-layout":`master-only`,"data-detail-open":`false`,className:a(`flex min-h-0 flex-1 overflow-hidden`,i),children:(0,N.jsx)(`div`,{"data-testid":`traffic-master`,className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:e})})}function Sl({className:e,orientation:t=`horizontal`,...n}){return(0,N.jsx)(ns,{"data-slot":`tabs`,"data-orientation":t,orientation:t,className:a(`group/tabs flex gap-2 data-[orientation=horizontal]:flex-col`,e),...n})}var Cl=u(`rounded-lg p-[3px] group-data-[orientation=horizontal]/tabs:h-9 data-[variant=line]:rounded-none group/tabs-list text-muted-foreground inline-flex w-fit items-center justify-center group-data-[orientation=vertical]/tabs:h-fit group-data-[orientation=vertical]/tabs:flex-col`,{variants:{variant:{default:`bg-muted`,line:`gap-1 bg-transparent`}},defaultVariants:{variant:`default`}});function wl({className:e,variant:t=`default`,...n}){return(0,N.jsx)(rs,{"data-slot":`tabs-list`,"data-variant":t,className:a(Cl({variant:t}),e),...n})}function Tl({className:e,...t}){return(0,N.jsx)(is,{"data-slot":`tabs-trigger`,className:a(`focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring text-foreground/60 hover:text-foreground dark:text-muted-foreground dark:hover:text-foreground relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-all group-data-[orientation=vertical]/tabs:w-full group-data-[orientation=vertical]/tabs:justify-start focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 group-data-[variant=default]/tabs-list:data-[state=active]:shadow-sm group-data-[variant=line]/tabs-list:data-[state=active]:shadow-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,`group-data-[variant=default]/tabs-list:data-[state=active]:border-primary/20 group-data-[variant=default]/tabs-list:data-[state=active]:bg-accent group-data-[variant=default]/tabs-list:data-[state=active]:text-accent-foreground`,`group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent group-data-[variant=line]/tabs-list:data-[state=active]:text-primary dark:group-data-[variant=line]/tabs-list:data-[state=active]:border-transparent`,`after:bg-primary after:absolute after:opacity-0 after:transition-opacity group-data-[orientation=horizontal]/tabs:after:inset-x-0 group-data-[orientation=horizontal]/tabs:after:bottom-[-5px] group-data-[orientation=horizontal]/tabs:after:h-0.5 group-data-[orientation=vertical]/tabs:after:inset-y-0 group-data-[orientation=vertical]/tabs:after:-right-1 group-data-[orientation=vertical]/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-[state=active]:after:opacity-100`,e),...t})}function El({className:e,...t}){return(0,N.jsx)(as,{"data-slot":`tabs-content`,className:a(`flex-1 outline-none`,e),...t})}function Dl({delayDuration:e=0,...t}){return(0,N.jsx)(ac,{"data-slot":`tooltip-provider`,delayDuration:e,...t})}function Ol({...e}){return(0,N.jsx)(Dl,{children:(0,N.jsx)(oc,{"data-slot":`tooltip`,...e})})}function kl({describe:e=!0,...t}){return(0,N.jsx)(sc,{"data-slot":`tooltip-trigger`,...t,...e?null:{"aria-describedby":t[`aria-describedby`]}})}function Al({className:e,sideOffset:t=0,children:n,...r}){return(0,N.jsx)(cc,{children:(0,N.jsxs)(lc,{"data-slot":`tooltip-content`,sideOffset:t,className:a(`bg-foreground text-background animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance`,e),...r,children:[n,(0,N.jsx)(uc,{className:`bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]`})]})})}var jl=Symbol.for(`react.lazy`),Ml=k.use;function Nl(e){return typeof e==`object`&&!!e&&`then`in e}function Pl(e){return typeof e==`object`&&!!e&&`$$typeof`in e&&e.$$typeof===jl&&`_payload`in e&&Nl(e._payload)}function Fl(e){let t=Il(e),n=k.forwardRef((e,n)=>{let{children:r,...i}=e;Pl(r)&&typeof Ml==`function`&&(r=Ml(r._payload));let a=k.Children.toArray(r),o=a.find(Rl);if(o){let e=o.props.children,r=a.map(t=>t===o?k.Children.count(e)>1?k.Children.only(null):k.isValidElement(e)?e.props.children:null:t);return(0,N.jsx)(t,{...i,ref:n,children:k.isValidElement(e)?k.cloneElement(e,void 0,r):null})}return(0,N.jsx)(t,{...i,ref:n,children:r})});return n.displayName=`${e}.Slot`,n}function Il(t){let n=k.forwardRef((t,n)=>{let{children:r,...i}=t;if(Pl(r)&&typeof Ml==`function`&&(r=Ml(r._payload)),k.isValidElement(r)){let t=Bl(r),a=zl(i,r.props);return r.type!==k.Fragment&&(a.ref=n?e(n,t):t),k.cloneElement(r,a)}return k.Children.count(r)>1?k.Children.only(null):null});return n.displayName=`${t}.SlotClone`,n}var Ll=Symbol(`radix.slottable`);function Rl(e){return k.isValidElement(e)&&typeof e.type==`function`&&`__radixId`in e.type&&e.type.__radixId===Ll}function zl(e,t){let n={...t};for(let r in t){let i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?n[r]=(...e)=>{let t=a(...e);return i(...e),t}:i&&(n[r]=i):r===`style`?n[r]={...i,...a}:r===`className`&&(n[r]=[i,a].filter(Boolean).join(` `))}return{...e,...n}}function Bl(e){let t=Object.getOwnPropertyDescriptor(e.props,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var W=[`a`,`button`,`div`,`form`,`h2`,`h3`,`img`,`input`,`label`,`li`,`nav`,`ol`,`p`,`select`,`span`,`svg`,`ul`].reduce((e,t)=>{let n=Fl(`Primitive.${t}`),r=k.forwardRef((e,r)=>{let{asChild:i,...a}=e,o=i?n:t;return typeof window<`u`&&(window[Symbol.for(`radix-ui`)]=!0),(0,N.jsx)(o,{...a,ref:r})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{}),G=`Label`,K=k.forwardRef((e,t)=>(0,N.jsx)(W.label,{...e,ref:t,onMouseDown:t=>{t.target.closest(`button, input, select, textarea`)||(e.onMouseDown?.(t),!t.defaultPrevented&&t.detail>1&&t.preventDefault())}}));K.displayName=G;var q=K,J=k.forwardRef(({className:e,...t},n)=>(0,N.jsx)(q,{ref:n,className:a(`text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70`,e),...t}));J.displayName=q.displayName;var Vl=400;function Hl({...e}){return(0,N.jsx)(ce,{"data-slot":`sheet`,...e})}function Ul({...e}){return(0,N.jsx)(ie,{"data-slot":`sheet-portal`,...e})}function Wl({className:e,...t}){return(0,N.jsx)(oe,{"data-slot":`sheet-overlay`,className:a(`sheet-glass-overlay data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-[90]`,e),...t})}function Gl({className:e,children:t,side:n=`right`,showCloseButton:r=!0,resizable:i=!1,defaultWidth:o=700,minWidth:s=Vl,maxWidth:c=1600,storageKey:l=`sheet-width`,...u}){let d=`sheet-w-${l}`,[f,p]=k.useState(()=>{if(typeof window>`u`||!i)return o;let e=localStorage.getItem(d);if(e){let t=parseInt(e,10);if(!isNaN(t))return Math.max(s,Math.min(c,t))}return o}),[m,h]=k.useState(!1),g=k.useRef(null);k.useEffect(()=>{if(!i||!m)return;let e=e=>{let t=window.innerWidth,r=n===`left`?e.clientX:t-e.clientX,i=Math.min(c,t*.92),a=Math.max(s,Math.min(i,r));p(a),localStorage.setItem(d,a.toString())},t=()=>{h(!1),document.body.style.cursor=``,document.body.style.userSelect=``};return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),document.body.style.cursor=`ew-resize`,document.body.style.userSelect=`none`,()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t),document.body.style.cursor=``,document.body.style.userSelect=``}},[m,i,s,c,d,n]);let _=e=>{e.preventDefault(),h(!0)};return(0,N.jsxs)(Ul,{children:[(0,N.jsx)(Wl,{}),(0,N.jsxs)(se,{ref:g,"data-slot":`sheet-content`,style:i&&(n===`right`||n===`left`)?{width:`${f}px`,maxWidth:`92vw`}:void 0,className:a(`sheet-glass-content data-[state=open]:animate-in data-[state=closed]:animate-out fixed z-[91] flex flex-col gap-4 transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500`,n===`right`&&!i&&`data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm`,n===`right`&&i&&`data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right inset-y-0 right-0 h-full border-l`,n===`left`&&!i&&`data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm`,n===`left`&&i&&`data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left inset-y-0 left-0 h-full border-r`,n===`top`&&`data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top inset-x-0 top-0 h-auto border-b`,n===`bottom`&&`data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom inset-x-0 bottom-0 h-auto border-t`,e),...u,children:[i&&(n===`right`||n===`left`)&&(0,N.jsx)(`div`,{className:a(`absolute top-0 bottom-0 w-1 cursor-ew-resize transition-colors z-10`,n===`right`?`left-0`:`right-0`,m?`bg-blue-500 w-1`:`hover:bg-blue-400/60`),onMouseDown:_,children:(0,N.jsx)(`div`,{className:a(`absolute top-0 bottom-0 w-5`,n===`right`?`left-0 -translate-x-2`:`right-0 translate-x-2`)})}),t,r&&(0,N.jsxs)(E,{className:`ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none`,children:[(0,N.jsx)(ae,{className:`size-4`}),(0,N.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function Y({className:e,...t}){return(0,N.jsx)(`div`,{"data-slot":`sheet-header`,className:a(`sheet-glass-header flex flex-col gap-1.5 border-b p-4`,e),...t})}function Kl({className:e,...t}){return(0,N.jsx)(T,{"data-slot":`sheet-title`,className:a(`text-foreground font-semibold`,e),...t})}function ql({className:e,...t}){return(0,N.jsx)(le,{"data-slot":`sheet-description`,className:a(`text-muted-foreground text-sm`,e),...t})}function Jl({className:e,orientation:t=`horizontal`,decorative:n=!0,...r}){return(0,N.jsx)(Bo,{"data-slot":`separator`,decorative:n,orientation:t,className:a(`bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px`,e),...r})}function Yl(e=globalThis.navigator){if(!e)return!1;let t=e.userAgentData?.platform;if(t)return/macOS|iOS|iPadOS/i.test(t);let n=e.platform||``;return/Mac|iPhone|iPad|iPod/i.test(n)?!0:/Mac OS|iPhone|iPad|iPod/i.test(e.userAgent||``)}function Xl(e){return Yl(e)?`⌘+S`:`Ctrl+S`}function Zl(e){return Yl(e)?`Meta+S`:`Control+S`}function Ql({className:e}){return(0,N.jsx)(`kbd`,{"aria-hidden":`true`,"data-slot":`save-shortcut`,className:a(`pointer-events-none ml-1 rounded border border-current/20 px-1 py-0.5 font-mono text-[10px] font-normal leading-none opacity-70`,e),children:Xl()})}function $l({children:e,...t}){return(0,N.jsxs)(d,{"aria-keyshortcuts":Zl(),...t,children:[e,(0,N.jsx)(Ql,{})]})}var eu=(0,k.createContext)(null),tu={page:100,panel:200,modal:300};function nu(e){let t=(0,k.useContext)(eu),n=(0,k.useId)();(0,k.useEffect)(()=>{if(t)return t.register(n),()=>t.unregister(n)},[n,t]),(0,k.useEffect)(()=>{t&&t.update(n,e)},[n,e,t])}function ru(){let e=Ee(),t=Te(e);return e.enabled?t?(0,N.jsxs)(fc,{variant:`outline`,children:[`AI: `,e.provider===`openai`?`OpenAI`:`Anthropic`]}):(0,N.jsx)(fc,{variant:`secondary`,children:`AI: 未配置`}):(0,N.jsx)(fc,{variant:`outline`,className:`text-xs`,children:`AI: 未启用`})}var iu={theme:`system`,accentColor:`auto`,fontSize:`medium`,detailBodySizeKB:256,aiConfig:{enabled:!1,provider:`openai`,apiKey:``,baseUrl:``,model:``,models:[]},mocksFilePath:``,pluginMode:`off`,clientAliases:{}},X=null;async function au(){try{let e=await fetch(`/api/settings`);if(e.ok){let t=await e.json(),n={...iu,...t,accentColor:t.accentColor||iu.accentColor,aiConfig:{...iu.aiConfig,...t.aiConfig}};return X=n,we(n.aiConfig),n}}catch(e){console.error(`加载设置失败:`,e)}let e=lu();return e?(X=e,ou(e).catch(console.error),e):(X={...iu},X)}async function ou(e){try{if((await fetch(`/api/settings`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)})).ok)X=e;else throw Error(`保存设置失败`)}catch(e){throw console.error(`保存设置失败:`,e),e}}function su(){return X||{...iu}}async function cu(e){let t=await fetch(`/api/settings`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(!t.ok)throw console.error(`保存设置失败:`,t.status),Error(`保存设置失败`);let n=await t.json().catch(()=>null);X={...iu,...X||{},...n?.settings||{},...e}}function lu(){try{let e=localStorage.getItem(`theme-storage`),t=localStorage.getItem(`font-size`),n=localStorage.getItem(`meddle-ai-config`);if(!e&&!t&&!n)return null;let r={...iu};if(e)try{r.theme=JSON.parse(e).theme||`system`}catch{}if(t&&(r.fontSize=t),n)try{r.aiConfig=JSON.parse(n)}catch{}return console.log(`已从 localStorage 迁移设置`),r}catch(e){return console.error(`迁移设置失败:`,e),null}}var uu=k.createContext(void 0);function du(e){if(!e)return 1;let t={small:.9,medium:1,large:1.1};if(e in t)return t[e];let n=Number(e);return!Number.isFinite(n)||n<=0?1:n>10?n/100:n}function fu(){return typeof window>`u`?`light`:window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`}function pu({children:e,defaultTheme:t=`system`}){let[n,r]=k.useState(()=>typeof window>`u`?t:su().theme||t),[i,a]=k.useState(()=>typeof window>`u`?`auto`:su().accentColor||`auto`),[o,s]=k.useState(!1),c=k.useCallback(e=>{window.document.documentElement.style.setProperty(`--app-scale`,String(e))},[]);k.useEffect(()=>{au().then(e=>{r(e.theme||t),a(e.accentColor||`auto`),c(du(e.fontSize)),s(!0)}).catch(()=>{s(!0)})},[t,c]);let[l,u]=k.useState(fu);k.useEffect(()=>{let e=window.matchMedia(`(prefers-color-scheme: dark)`),t=()=>u(fu());return t(),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let d=n===`system`?l:n;k.useEffect(()=>{if(!o)return;let e=window.document.documentElement;e.classList.remove(`light`,`dark`),e.classList.add(d),e.dataset.accent=i,cu({theme:n,accentColor:i}).catch(console.error)},[n,d,i,o]);let f=k.useCallback(e=>{r(e)},[]),p=k.useCallback(e=>{a(e)},[]),m=k.useCallback(()=>{r(e=>e===`light`?`dark`:e===`dark`?`system`:`light`)},[]),h=k.useMemo(()=>({theme:n,resolvedTheme:d,accentColor:i,setTheme:f,setAccentColor:p,toggleTheme:m,setZoom:c}),[n,d,i,f,p,m,c]);return(0,N.jsx)(uu.Provider,{value:h,children:e})}function mu(){let e=k.useContext(uu);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e}function hu(){let[e,t]=(0,k.useState)(!1),[n,r]=(0,k.useState)(!1),[i,a]=(0,k.useState)(null),[o,s]=(0,k.useState)(null),c=(0,k.useRef)(null),l=(0,k.useCallback)(async()=>{r(!0),s(null);try{let e=await fetch(`/api/sessions`,{cache:`no-store`});if(!e.ok)throw Error(`HTTP ${e.status}`);a(await e.json())}catch(e){s(e.message)}finally{r(!1)}},[]);(0,k.useEffect)(()=>{if(!e)return;l();let n=e=>{c.current&&!c.current.contains(e.target)&&t(!1)},r=e=>{e.key===`Escape`&&t(!1)};return document.addEventListener(`mousedown`,n),document.addEventListener(`keydown`,r),()=>{document.removeEventListener(`mousedown`,n),document.removeEventListener(`keydown`,r)}},[e,l]);let u=i?.current.isDefault?`Default`:i?.current.id??`Session`,f=e=>{window.open(`http://127.0.0.1:${e}/`,`_blank`,`noopener`)},p=i?.sessions.filter(e=>e.id!==i.current.id)??[];return(0,N.jsxs)(`div`,{ref:c,className:`relative`,children:[(0,N.jsxs)(d,{variant:`outline`,size:`sm`,onClick:()=>t(e=>!e),title:`切换 session`,children:[(0,N.jsx)(Nr,{"data-icon":`inline-start`}),(0,N.jsx)(`span`,{className:`hidden sm:inline`,children:u})]}),e&&(0,N.jsxs)(`div`,{className:`absolute right-0 top-full z-50 mt-1 w-80 rounded-md border bg-popover p-1 text-popover-foreground shadow-md`,children:[(0,N.jsx)(`div`,{className:`px-2 py-1.5 text-xs font-medium text-muted-foreground`,children:`当前 session`}),i&&(0,N.jsxs)(`div`,{className:`flex items-center justify-between rounded-sm px-2 py-1.5`,children:[(0,N.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,N.jsx)(y,{className:`size-3.5 text-primary shrink-0`}),(0,N.jsx)(`span`,{className:`truncate text-sm`,children:i.current.isDefault?`Default`:i.current.id})]}),(0,N.jsxs)(fc,{variant:`secondary`,className:`shrink-0`,children:[`:`,i.current.port]})]}),(0,N.jsx)(`div`,{className:`my-1 h-px bg-border`}),(0,N.jsx)(`div`,{className:`px-2 py-1.5 text-xs font-medium text-muted-foreground`,children:`其他 session`}),n&&(0,N.jsxs)(`div`,{className:`space-y-1 px-1 py-1`,children:[(0,N.jsx)(Ai,{className:`h-8 w-full`}),(0,N.jsx)(Ai,{className:`h-8 w-full`})]}),o&&(0,N.jsxs)(`div`,{className:`px-2 py-2 text-xs text-destructive`,children:[`加载失败: `,o]}),!n&&!o&&p.length===0&&(0,N.jsxs)(`div`,{className:`px-2 py-2 text-xs text-muted-foreground`,children:[`暂无其他 session。用 `,(0,N.jsx)(`code`,{className:`rounded bg-muted px-1`,children:`meddle session create`}),` 创建。`]}),!n&&!o&&p.map(e=>(0,N.jsxs)(`button`,{onClick:()=>f(e.port),className:`flex w-full items-center justify-between gap-2 rounded-sm px-2 py-1.5 text-left hover:bg-accent`,children:[(0,N.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,N.jsx)(`span`,{className:`size-2 shrink-0 rounded-full ${e.alive?`bg-green-500`:`bg-red-500`}`,title:e.alive?`running`:`orphaned`}),(0,N.jsxs)(`div`,{className:`min-w-0`,children:[(0,N.jsx)(`div`,{className:`truncate text-sm`,children:e.label||e.id}),(0,N.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:e.id})]})]}),(0,N.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:[(0,N.jsxs)(fc,{variant:`secondary`,children:[`:`,e.port]}),(0,N.jsx)(Hr,{className:`size-3.5 text-muted-foreground`})]})]},e.id))]})]})}var gu=[{tab:`logs`,path:`/logs`,label:`流量`,mode:`work`,title:`查看经过代理的本机、远程设备和插件测试流量`},{tab:`config`,path:`/config`,label:`路由规则`,mode:`config`,title:`管理代理转发规则,并在表格、文本和图表视图间切换`},{tab:`mock`,path:`/mock`,label:`Mock`,mode:`config`,title:`匹配请求后返回本地响应,用于联调和异常场景测试`},{tab:`plugins`,path:`/plugins`,label:`扩展插件`,mode:`config`,title:`控制内置、自定义和第三方插件的运行状态`},{tab:`health`,path:`/health`,label:`健康`,mode:`config`,title:`查看进程健康、连接、守护策略和日志限流状态`},{tab:`mobile`,path:`/mobile`,label:`手机代理`,mode:`config`,title:`扫码配置手机代理并安装 HTTPS 根证书`},{tab:`settings`,path:`/settings`,label:`设置`,mode:`config`,title:`管理系统偏好、配置文件和 AI 功能`}],_u={"/":`logs`,"/logs":`logs`,"/config":`config`,"/mock":`mock`,"/plugins":`plugins`,"/health":`health`,"/settings":`settings`,"/mobile":`mobile`},vu={logs:`/logs`,config:`/config`,mock:`/mock`,plugins:`/plugins`,health:`/health`,settings:`/settings`,mobile:`/mobile`};function yu(e){return _u[e]??`logs`}function bu(e){return vu[e]??`/logs`}function xu(e){return e===`logs`?`work`:`config`}var Su=`meddle-shell-nav-collapsed`,Cu=`(max-width: 1023.98px)`;function wu(){try{return localStorage.getItem(Su)===`1`}catch{return!1}}function Tu(e){try{localStorage.setItem(Su,e?`1`:`0`)}catch{}}var Eu={logs:qr,config:Wr,mock:Rr,plugins:ui,health:Or,mobile:fi,settings:gi};function Du({activeTab:e,onTabChange:t,mockEnabledCount:n=0}){let[r,i]=(0,k.useState)(wu),o=bl(Cu),[s,c]=(0,k.useState)(!1),l=(0,k.useRef)(null),u=(0,k.useRef)(null),f=o&&s,p=o?!s:r,[m,h]=(0,k.useState)(o);m!==o&&(h(o),c(!1)),(0,k.useEffect)(()=>{if(!f)return;let e=l.current?.querySelector(`#app-shell-nav`);(e?.querySelector(`[aria-current="page"]`)??e?.querySelector(`[role="tab"]`))?.focus()},[f]),(0,k.useEffect)(()=>{if(!f)return;let e=e=>{let t=e.target;t&&l.current?.contains(t)||(c(!1),window.setTimeout(()=>{let e=document.activeElement;(!e||e===document.body||l.current?.contains(e))&&u.current?.focus()},0))},t=e=>{e.key===`Escape`&&(e.preventDefault(),c(!1),u.current?.focus())};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[f]);let g=()=>{if(o){c(e=>!e);return}i(e=>{let t=!e;return Tu(t),t})},_=e=>{t(e),f&&(c(!1),window.setTimeout(()=>u.current?.focus(),0))},v=t=>{let r=Eu[t.tab],i=e===t.tab,o=t.tab===`mock`&&n>0,s=n>99?`99+`:String(n),c=o?`${t.label},${n} 条启用`:void 0,l=e=>(0,N.jsx)(`span`,{"data-slot":`shell-nav-mock-count`,className:`inline-block min-w-[2ch] text-center tabular-nums`,children:e}),u=(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(r,{"aria-hidden":!0}),o&&p?(0,N.jsx)(fc,{variant:`secondary`,"data-testid":`shell-nav-mock-badge`,"aria-hidden":!0,className:`pointer-events-none absolute -top-1 -right-1 h-[16px] min-w-[16px] px-1 text-[10px] leading-none`,children:l(s)}):null,(0,N.jsx)(`span`,{"data-slot":`shell-nav-label`,className:p?`sr-only`:void 0,children:t.label}),t.tab===`mock`&&!p?(0,N.jsx)(fc,{variant:`secondary`,"data-testid":o?`shell-nav-mock-badge`:`shell-nav-mock-badge-slot`,"aria-hidden":!0,className:a(`h-5 px-1.5 text-[10px]`,!o&&`invisible`),children:l(o?s:null)}):null]});return(0,N.jsxs)(Ol,{...p?{}:{open:!1},children:[(0,N.jsx)(Tl,{asChild:!0,value:t.tab,"data-testid":`shell-nav-${t.tab}`,"aria-label":c,"data-shell-nav-mode":t.mode,title:p?void 0:t.title,"aria-current":i?`page`:void 0,className:a(`relative h-auto min-h-10 w-full flex-none gap-2.5 px-3.5 py-3`,p&&`justify-center px-2.5`),children:(0,N.jsx)(kl,{describe:!1,children:u})}),(0,N.jsx)(Al,{side:`right`,sideOffset:8,"data-testid":`shell-nav-tooltip-${t.tab}`,children:t.label})]},t.tab)};return(0,N.jsx)(`div`,{ref:l,"data-testid":`app-shell-nav-rail`,"data-collapsed":p?`true`:`false`,"data-narrow":o?`true`:`false`,"data-overlay":f?`true`:`false`,className:a(`relative flex h-full min-h-0 shrink-0 flex-col self-stretch`,o?`w-14`:`w-fit`),children:(0,N.jsxs)(`div`,{"data-testid":`app-shell-nav-panel`,className:a(`flex h-full min-h-0 flex-col`,f&&`absolute inset-y-0 left-0 z-30 w-max border-r bg-background shadow-overlay-edge`),children:[(0,N.jsx)(Sl,{orientation:`vertical`,value:e,onValueChange:_,activationMode:f?`manual`:`automatic`,className:`h-full min-h-0 flex-1 flex-col`,children:(0,N.jsx)(wl,{id:`app-shell-nav`,"data-testid":`app-shell-nav`,"aria-label":`主导航`,className:a(`!h-full w-fit flex-col items-stretch justify-start gap-2.5 overflow-y-auto bg-transparent p-2.5`,p&&`w-14 overflow-x-hidden`),children:gu.map(v)})}),(0,N.jsx)(d,{ref:u,type:`button`,variant:`ghost`,size:p?`icon`:`sm`,className:a(`mt-2 mb-2.5 shrink-0`,p?`size-10 self-center`:`mx-2.5 h-10 w-auto justify-start px-3.5`),"data-testid":`shell-nav-collapse`,"aria-expanded":!p,"aria-controls":`app-shell-nav`,"aria-label":p?`展开菜单`:`收起菜单`,title:p?`展开菜单`:`收起菜单`,onClick:g,children:p?(0,N.jsx)(ai,{}):(0,N.jsx)(ii,{})})]})})}function Ou({onCommandClick:e}){let{theme:t,toggleTheme:n}=mu();return(0,N.jsx)(`header`,{"data-testid":`app-shell-header`,className:`sticky top-0 z-40 border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80`,children:(0,N.jsxs)(`div`,{className:`flex h-14 w-full items-center gap-3 px-4 lg:px-6`,children:[(0,N.jsxs)(`div`,{className:`flex min-w-0 shrink-0 items-center gap-3`,children:[(0,N.jsx)(`div`,{className:`flex size-8 shrink-0 items-center justify-center rounded-lg bg-primary text-primary-foreground shadow-sm`,children:(0,N.jsx)(qr,{className:`size-4`})}),(0,N.jsxs)(`div`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,N.jsx)(`h1`,{className:`truncate text-sm font-semibold tracking-tight`,children:`Meddle`}),(0,N.jsx)(`span`,{className:`hidden text-xs text-muted-foreground xl:inline`,children:`开发代理工具`})]})]}),(0,N.jsxs)(`button`,{type:`button`,onClick:e,className:`hidden h-9 w-72 items-center gap-2 rounded-md border border-input bg-transparent px-3 text-left text-sm text-muted-foreground shadow-xs outline-none transition-colors hover:bg-muted/40 focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 sm:inline-flex`,title:`打开全局操作面板`,"data-testid":`shell-command`,children:[(0,N.jsx)(hi,{className:`size-4 shrink-0`,"aria-hidden":!0}),(0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:`搜索操作…`}),(0,N.jsx)(fc,{variant:`secondary`,children:`⌘K`})]}),(0,N.jsxs)(`div`,{"data-testid":`app-shell-utilities`,className:`ml-auto flex shrink-0 items-center gap-2`,children:[(0,N.jsx)(ru,{}),(0,N.jsx)(hu,{}),(0,N.jsx)(d,{variant:`ghost`,size:`icon-sm`,onClick:n,"aria-label":`当前主题: ${t},点击切换`,title:`主题: ${t===`system`?`跟随系统`:t===`light`?`浅色`:`深色`}`,children:t===`light`?(0,N.jsx)(ti,{}):t===`dark`?(0,N.jsx)(yi,{}):(0,N.jsx)(ei,{})})]})]})})}var ku=`/api/ping`,Au=2500,ju=3e3;function Mu(){return{consecutiveFailures:0,unreachable:!1}}function Nu(e,t,n=3){if(t)return{consecutiveFailures:0,unreachable:!1};let r=e.consecutiveFailures+1;return{consecutiveFailures:r,unreachable:r>=n}}async function Pu(e={}){let t=e.path??`/api/ping`,n=e.timeoutMs??3e3,r=e.fetchImpl??fetch,i=new AbortController,a=()=>i.abort();e.signal&&(e.signal.aborted?i.abort():e.signal.addEventListener(`abort`,a,{once:!0}));let o=setTimeout(()=>i.abort(),n);try{return(await r(t,{method:`GET`,cache:`no-store`,signal:i.signal})).ok}catch{return!1}finally{clearTimeout(o),e.signal?.removeEventListener(`abort`,a)}}function Fu(e={}){let{enabled:t=!0,intervalMs:n=Au,failureThreshold:r=3,timeoutMs:i=ju,path:a=ku,fetchImpl:o}=e,[s,c]=(0,k.useState)(Mu);return(0,k.useEffect)(()=>{if(!t)return;let e=!1,s=new AbortController,l,u=async()=>{let t=await Pu({path:a,timeoutMs:i,signal:s.signal,fetchImpl:o});e||(c(e=>Nu(e,t,r)),e||(l=setTimeout(()=>{u()},n)))};return u(),()=>{e=!0,s.abort(),l!==void 0&&clearTimeout(l)}},[t,n,i,a,o,r]),{unreachable:t?s.unreachable:!1,consecutiveFailures:t?s.consecutiveFailures:0}}var Iu=`连不上 Meddle 服务,正在重试。请确认 meddle 仍在运行`;function Lu(){let{unreachable:e}=Fu();return e?(0,N.jsx)(`div`,{role:`status`,"aria-live":`polite`,"data-testid":`backend-heartbeat-banner`,className:`shrink-0 border-b border-destructive/40 bg-destructive/10 px-4 py-2 text-sm text-destructive`,children:(0,N.jsxs)(`div`,{className:`mx-auto flex max-w-[1600px] items-center justify-center gap-2`,children:[(0,N.jsx)(Si,{className:`size-4 shrink-0`,"aria-hidden":!0}),(0,N.jsx)(`p`,{children:Iu})]})}):null}var Ru=1e4;function zu(e,t,n){if(t.length===0)return e;let r=Math.max(0,n);if(r===0)return[];let i=Math.min(t.length,r),a=Math.min(e.length,r-i),o=Array(i+a);for(let e=0;e<i;e++)o[e]=t[t.length-1-e];for(let t=0;t<a;t++)o[i+t]=e[t];return o}function Bu(e,t,n){let r=Math.max(0,n);if(r===0)return[];if(e.length===0)return t.length<=r?t:t.slice(0,r);let i=[],a=new Set,o=e=>{if(!(i.length>=r)){if(typeof e.id==`number`){if(a.has(e.id))return;a.add(e.id)}i.push(e)}};for(let t of e)o(t);for(let e of t)o(e);return i}function Vu(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.id==`number`&&typeof t.method==`string`&&typeof t.source==`string`&&typeof t.target==`string`&&typeof t.time==`string`}function Hu(e=Ru){let[t,n]=(0,k.useState)([]),[r,i]=(0,k.useState)(null),[a,o]=(0,k.useState)(null),[s,c]=(0,k.useState)(!1),[l,u]=(0,k.useState)(null),d=(0,k.useRef)(e),f=(0,k.useRef)(null),p=(0,k.useRef)([]);return(0,k.useEffect)(()=>{d.current=e},[e]),(0,k.useEffect)(()=>{let e=new AbortController;return fetch(`/api/logs`,{signal:e.signal}).then(e=>e.json()).then(e=>{n(t=>Bu(t,e,d.current))}).catch(e=>{e instanceof DOMException&&e.name===`AbortError`||console.error(e)}),()=>e.abort()},[]),(0,k.useEffect)(()=>{let e=null,t=null,r=0,i=()=>{t=null;let e=p.current;e.length!==0&&(p.current=[],n(t=>zu(t,e,d.current)))},a=()=>{t||=setTimeout(i,50)},o=()=>{let t=location.protocol===`https:`?`wss://`:`ws://`,n=new WebSocket(t+location.host+`/ws`);n.addEventListener(`message`,e=>{try{let t=JSON.parse(e.data);if(t&&t.type===`mocksUpdated`){window.dispatchEvent(new CustomEvent(`mocksUpdated`,{detail:t.rules??[]}));return}if(!Vu(t))return;p.current.push(t),a()}catch(e){console.error(`Failed to parse WebSocket message:`,e)}}),n.addEventListener(`error`,e=>{console.error(`WebSocket error:`,e)}),n.addEventListener(`close`,()=>{if(console.log(`WebSocket closed`),f.current=null,r<10){let t=Math.min(1e3*2**r,3e4);console.log(`Reconnecting in ${t}ms (attempt ${r+1}/10)`),e=setTimeout(()=>{r++,o()},t)}else console.error(`Max reconnection attempts reached`)}),n.addEventListener(`open`,()=>{console.log(`WebSocket connected`),r=0}),f.current=n};return o(),()=>{e&&clearTimeout(e),t&&clearTimeout(t),p.current=[],f.current&&=(f.current.close(),null)}},[]),{records:t,selectedRecordId:r,recordDetail:a,detailLoading:s,detailError:l,fetchDetail:(0,k.useCallback)(async e=>{i(e),c(!0),o(null),u(null);try{let t=await fetch(`/api/logs/${e}`),n=await t.json();if(!t.ok)throw Error(n?.error||`加载详情失败 (${t.status})`);o(n)}catch(e){u(e instanceof Error?e.message:`加载详情失败`),console.error(`Failed to fetch detail:`,e)}finally{c(!1)}},[]),closeDetail:(0,k.useCallback)(()=>{i(null),o(null)},[]),clearRecords:(0,k.useCallback)(()=>{p.current=[],n([])},[]),replayRequest:(0,k.useCallback)(async e=>{let t=await(await fetch(`/api/replay/${e}`,{method:`POST`})).json();if(t.status===`success`)return t;throw Error(t.error||`重放请求失败`)},[])}}var Uu=/^(?:\d{1,3}\.){3}\d{1,3}$/,Wu=/^(?:[0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}(?:%[\w.-]+)?$/,Z=/^[A-Za-z0-9_.-]+$/;function Gu(e){return Uu.test(e)||Wu.test(e)}function Ku(e){return e.includes(`:`)&&!e.startsWith(`[`)?`[${e}]`:e}function qu(e){let t=e.indexOf(`#`);return(t>=0?e.slice(0,t):e).trim()}function Ju(e){let t=qu(e);if(!t)return null;let[n,...r]=t.split(/\s+/).filter(Boolean);return!n||r.length===0||!Gu(n)||!r.every(e=>Z.test(e))?null:`${r.join(` `)} ${Ku(n)}`}function Yu(e){let t=!1,n=e.split(/\r?\n/).map(e=>{let n=Ju(e);return n?(t=!0,n):e}).join(`
|
|
17
|
-
`);return t?n:e}function
|
|
18
|
-
`)}var
|
|
16
|
+
`)}function pl(e){return e.applicationIdentitySource===`user-agent`}function ml({records:e,selectedRecordId:t,onSelect:n,autoScroll:r}){let i=(0,k.useRef)(null),o=(0,k.useRef)(e.length),s=(0,k.useRef)(!0),[c,l]=(0,k.useState)(`desc`),u=Wc({count:e.length,getScrollElement:()=>i.current?.querySelector(`[data-radix-scroll-area-viewport]`),estimateSize:()=>22,overscan:10}),f=u.getVirtualItems();return(0,k.useEffect)(()=>{let e=i.current?.querySelector(`[data-radix-scroll-area-viewport]`);if(!(e instanceof HTMLElement))return;let t=()=>{s.current=c===`desc`?e.scrollTop<=sl:e.scrollHeight-e.scrollTop-e.clientHeight<=sl};return t(),e.addEventListener(`scroll`,t,{passive:!0}),()=>e.removeEventListener(`scroll`,t)},[c]),(0,k.useEffect)(()=>{if(r&&s.current&&e.length>o.current){let e=i.current?.querySelector(`[data-radix-scroll-area-viewport]`);e&&requestAnimationFrame(()=>{e.scrollTop=c===`desc`?0:e.scrollHeight})}o.current=e.length},[e.length,r,c]),(0,N.jsx)(`div`,{className:`meddle-thin-scroll relative flex min-h-0 flex-1 overflow-x-auto`,children:(0,N.jsxs)(`div`,{className:`flex min-h-0 min-w-[960px] flex-1 flex-col`,children:[(0,N.jsxs)(`div`,{className:`z-10 flex h-7 shrink-0 items-stretch border-b bg-muted/70 text-[11px] font-medium backdrop-blur supports-[backdrop-filter]:bg-muted/90`,children:[(0,N.jsx)(`div`,{className:a(H,`w-16`),children:`方法`}),(0,N.jsx)(`div`,{className:a(H,`w-14`),children:`状态`}),(0,N.jsx)(`div`,{className:a(H,`w-24`),children:`来源`}),(0,N.jsx)(`div`,{className:a(H,`w-44`),children:`应用`}),(0,N.jsx)(`div`,{className:a(H,`min-w-[200px] flex-1`),children:`源地址`}),(0,N.jsx)(`div`,{className:a(H,`min-w-[200px] flex-1`),children:`目标地址`}),(0,N.jsx)(`div`,{className:a(H,`w-14`),children:`协议`}),(0,N.jsx)(`div`,{className:a(H,`w-16`),children:`耗时`}),(0,N.jsx)(`div`,{className:a(H,`w-24`),children:(0,N.jsxs)(d,{variant:`ghost`,size:`xs`,onClick:()=>{let e=c===`desc`?`asc`:`desc`;s.current=e===`desc`,l(e),u.scrollToOffset(0)},className:`-ml-1 h-6 px-1.5 text-[11px]`,title:c===`desc`?`倒序(新→旧),点击切换为正序`:`正序(旧→新),点击切换为倒序`,children:[`时间`,c===`desc`?(0,N.jsx)(Ar,{"data-icon":`inline-end`}):(0,N.jsx)(jr,{"data-icon":`inline-end`})]})}),(0,N.jsx)(`div`,{className:a(H,`w-14`),children:`命中`})]}),(0,N.jsx)(Qc,{className:`min-h-0 flex-1`,ref:i,children:(0,N.jsx)(`div`,{className:`min-w-full`,children:e.length===0?(0,N.jsx)(Gc,{className:`min-h-72 border-0`,children:(0,N.jsxs)(Kc,{children:[(0,N.jsx)(Jc,{variant:`icon`,children:(0,N.jsx)(Yr,{})}),(0,N.jsx)(Yc,{children:`暂无请求记录`}),(0,N.jsx)(Xc,{children:`打开需要调试的页面后,请求会实时显示在这里。`})]})}):(0,N.jsx)(`div`,{style:{height:`${u.getTotalSize()}px`,position:`relative`},children:f.map(r=>{let i=e[c===`desc`?r.index:e.length-1-r.index];return(0,N.jsxs)(`div`,{className:a(`absolute flex w-full items-center cursor-pointer border-b border-border/40 text-[11px] transition-colors`,t===i.id?`bg-accent`:`hover:bg-muted/50`),onClick:()=>i.id!=null&&n(i.id),style:{height:`${r.size}px`,transform:`translateY(${r.start}px)`},children:[(0,N.jsx)(`div`,{className:`flex h-full w-16 items-center px-2`,children:(0,N.jsx)(fc,{variant:cl(i.method),className:ol,children:i.method})}),(0,N.jsx)(`div`,{className:`flex h-full w-14 items-center px-2`,children:i.statusCode!=null&&(0,N.jsx)(fc,{variant:ll(i.statusCode),className:ol,children:i.statusCode})}),(0,N.jsx)(`div`,{className:`flex h-full w-24 items-center truncate px-2`,title:[i.clientName,i.clientIp].filter(Boolean).join(` · `)||`未标记来源`,children:(0,N.jsx)(fc,{variant:dl(i),className:a(ol,`max-w-full`),children:(0,N.jsx)(`span`,{className:`truncate`,children:ul(i)})})}),(0,N.jsx)(`div`,{className:`flex h-full w-44 items-center gap-1.5 truncate px-2`,title:fl(i)||(i.clientType===`plugin`?``:`未识别到请求应用`),children:i.applicationName?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(tl,{record:i,compact:!0}),(0,N.jsx)(`span`,{className:`truncate`,children:i.applicationName}),pl(i)&&(0,N.jsx)(`span`,{className:`shrink-0 rounded border px-1 text-[9px] leading-4 text-muted-foreground`,children:`推断`})]}):(0,N.jsx)(`span`,{className:`truncate text-muted-foreground`,children:i.clientType===`plugin`?`—`:`未知应用`})}),(0,N.jsxs)(`div`,{className:`flex h-full min-w-[200px] flex-1 items-center truncate px-2 font-mono`,title:i.source,children:[i._fromPluginTest&&(0,N.jsx)(fc,{variant:`secondary`,className:a(ol,`mr-1`),children:`插件测试`}),i.source]}),(0,N.jsx)(`div`,{className:`flex h-full min-w-[200px] flex-1 items-center truncate px-2 font-mono`,title:i.target,children:i.target}),(0,N.jsx)(`div`,{className:`flex h-full w-14 items-center px-2`,children:i.protocol&&(0,N.jsx)(fc,{variant:i.protocol===`h2`?`secondary`:`outline`,className:ol,children:i.protocol})}),(0,N.jsx)(`div`,{className:`flex h-full w-16 items-center px-2 font-mono text-[10px] text-muted-foreground`,children:i.duration!=null&&U(i.duration)}),(0,N.jsx)(`div`,{className:`flex h-full w-24 items-center px-1.5 font-mono text-[10px] text-muted-foreground`,children:i.time}),(0,N.jsx)(`div`,{className:`flex h-full w-14 items-center px-1.5`,children:(0,N.jsx)(al,{record:i})})]},i.id??r.index)})})})})]})})}var hl=`meddle-traffic-split-pct`;function gl(e){return Number.isFinite(e)?Math.max(35,Math.min(75,Math.round(e))):60}function _l(){if(typeof window>`u`)return 60;try{let e=localStorage.getItem(hl);return e==null?60:gl(parseFloat(e))}catch{return 60}}function vl(e){let t=gl(e);try{localStorage.setItem(hl,String(t))}catch{}return t}function yl(e,t,n){return n<=0?60:gl((e-t)/n*100)}function bl(e){let[t,n]=(0,k.useState)(()=>typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(e).matches);return(0,k.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let t=window.matchMedia(e),r=()=>n(t.matches);return r(),t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t}function xl({master:e,detail:t,drawer:n,detailOpen:r=!0,className:i}){let o=bl(`(max-width: 900px)`),s=(0,k.useRef)(null),[c,l]=(0,k.useState)(_l),[u,d]=(0,k.useState)(!1);(0,k.useEffect)(()=>{if(!u)return;let e=e=>{let t=s.current;if(!t)return;let n=t.getBoundingClientRect();l(yl(e.clientX,n.left,n.width))},t=()=>{d(!1),l(e=>vl(e)),document.body.style.cursor=``,document.body.style.userSelect=``};return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`,()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t),document.body.style.cursor=``,document.body.style.userSelect=``}},[u]);let f=(0,k.useCallback)(e=>{e.preventDefault(),d(!0)},[]);return o?(0,N.jsxs)(`div`,{"data-testid":`traffic-work-layout`,"data-layout":`narrow`,"data-detail-open":r?`true`:`false`,className:a(`flex min-h-0 flex-1 flex-col overflow-hidden`,i),children:[(0,N.jsx)(`div`,{"data-testid":`traffic-master`,className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:e}),n]}):r?(0,N.jsxs)(`div`,{ref:s,"data-testid":`traffic-work-layout`,"data-layout":`split`,"data-detail-open":`true`,"data-split-pct":c,className:a(`flex min-h-0 flex-1 overflow-hidden`,i),children:[(0,N.jsx)(`div`,{"data-testid":`traffic-master`,className:`flex min-h-0 min-w-0 shrink-0 flex-col overflow-hidden`,style:{flex:`0 0 ${c}%`,width:`${c}%`},children:e}),(0,N.jsxs)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-valuenow":c,"aria-valuemin":35,"aria-valuemax":75,"aria-label":`调整流量列表与详情分栏宽度`,"data-testid":`traffic-split-handle`,className:`group relative z-10 w-px shrink-0 cursor-col-resize`,onMouseDown:f,children:[(0,N.jsx)(`div`,{"aria-hidden":!0,className:a(`pointer-events-none absolute inset-0 bg-border transition-colors`,u?`bg-primary`:`group-hover:bg-transparent`)}),(0,N.jsx)(`div`,{"aria-hidden":!0,className:a(`pointer-events-none absolute inset-y-0 left-1/2 w-1 -translate-x-1/2 opacity-0 transition-opacity`,u?`bg-primary opacity-100`:`bg-primary/60 group-hover:opacity-100`)}),(0,N.jsx)(`div`,{className:`absolute inset-y-0 -left-1.5 -right-1.5`})]}),(0,N.jsx)(`div`,{"data-testid":`traffic-detail`,className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:t})]}):(0,N.jsx)(`div`,{"data-testid":`traffic-work-layout`,"data-layout":`master-only`,"data-detail-open":`false`,className:a(`flex min-h-0 flex-1 overflow-hidden`,i),children:(0,N.jsx)(`div`,{"data-testid":`traffic-master`,className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:e})})}function Sl({className:e,orientation:t=`horizontal`,...n}){return(0,N.jsx)(ns,{"data-slot":`tabs`,"data-orientation":t,orientation:t,className:a(`group/tabs flex gap-2 data-[orientation=horizontal]:flex-col`,e),...n})}var Cl=u(`rounded-lg p-[3px] group-data-[orientation=horizontal]/tabs:h-9 data-[variant=line]:rounded-none group/tabs-list text-muted-foreground inline-flex w-fit items-center justify-center group-data-[orientation=vertical]/tabs:h-fit group-data-[orientation=vertical]/tabs:flex-col`,{variants:{variant:{default:`bg-muted`,line:`gap-1 bg-transparent`}},defaultVariants:{variant:`default`}});function wl({className:e,variant:t=`default`,...n}){return(0,N.jsx)(rs,{"data-slot":`tabs-list`,"data-variant":t,className:a(Cl({variant:t}),e),...n})}function Tl({className:e,...t}){return(0,N.jsx)(is,{"data-slot":`tabs-trigger`,className:a(`focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring text-foreground/60 hover:text-foreground dark:text-muted-foreground dark:hover:text-foreground relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-all group-data-[orientation=vertical]/tabs:w-full group-data-[orientation=vertical]/tabs:justify-start focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 group-data-[variant=default]/tabs-list:data-[state=active]:shadow-sm group-data-[variant=line]/tabs-list:data-[state=active]:shadow-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,`group-data-[variant=default]/tabs-list:data-[state=active]:border-primary/20 group-data-[variant=default]/tabs-list:data-[state=active]:bg-accent group-data-[variant=default]/tabs-list:data-[state=active]:text-accent-foreground`,`group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent group-data-[variant=line]/tabs-list:data-[state=active]:text-primary dark:group-data-[variant=line]/tabs-list:data-[state=active]:border-transparent`,`after:bg-primary after:absolute after:opacity-0 after:transition-opacity group-data-[orientation=horizontal]/tabs:after:inset-x-0 group-data-[orientation=horizontal]/tabs:after:bottom-[-5px] group-data-[orientation=horizontal]/tabs:after:h-0.5 group-data-[orientation=vertical]/tabs:after:inset-y-0 group-data-[orientation=vertical]/tabs:after:-right-1 group-data-[orientation=vertical]/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-[state=active]:after:opacity-100`,e),...t})}function El({className:e,...t}){return(0,N.jsx)(as,{"data-slot":`tabs-content`,className:a(`flex-1 outline-none`,e),...t})}function Dl({delayDuration:e=0,...t}){return(0,N.jsx)(ac,{"data-slot":`tooltip-provider`,delayDuration:e,...t})}function Ol({...e}){return(0,N.jsx)(Dl,{children:(0,N.jsx)(oc,{"data-slot":`tooltip`,...e})})}function kl({describe:e=!0,...t}){return(0,N.jsx)(sc,{"data-slot":`tooltip-trigger`,...t,...e?null:{"aria-describedby":t[`aria-describedby`]}})}function Al({className:e,sideOffset:t=0,children:n,...r}){return(0,N.jsx)(cc,{children:(0,N.jsxs)(lc,{"data-slot":`tooltip-content`,sideOffset:t,className:a(`bg-foreground text-background animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance`,e),...r,children:[n,(0,N.jsx)(uc,{className:`bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]`})]})})}var jl=Symbol.for(`react.lazy`),Ml=k.use;function Nl(e){return typeof e==`object`&&!!e&&`then`in e}function Pl(e){return typeof e==`object`&&!!e&&`$$typeof`in e&&e.$$typeof===jl&&`_payload`in e&&Nl(e._payload)}function Fl(e){let t=Il(e),n=k.forwardRef((e,n)=>{let{children:r,...i}=e;Pl(r)&&typeof Ml==`function`&&(r=Ml(r._payload));let a=k.Children.toArray(r),o=a.find(Rl);if(o){let e=o.props.children,r=a.map(t=>t===o?k.Children.count(e)>1?k.Children.only(null):k.isValidElement(e)?e.props.children:null:t);return(0,N.jsx)(t,{...i,ref:n,children:k.isValidElement(e)?k.cloneElement(e,void 0,r):null})}return(0,N.jsx)(t,{...i,ref:n,children:r})});return n.displayName=`${e}.Slot`,n}function Il(t){let n=k.forwardRef((t,n)=>{let{children:r,...i}=t;if(Pl(r)&&typeof Ml==`function`&&(r=Ml(r._payload)),k.isValidElement(r)){let t=Bl(r),a=zl(i,r.props);return r.type!==k.Fragment&&(a.ref=n?e(n,t):t),k.cloneElement(r,a)}return k.Children.count(r)>1?k.Children.only(null):null});return n.displayName=`${t}.SlotClone`,n}var Ll=Symbol(`radix.slottable`);function Rl(e){return k.isValidElement(e)&&typeof e.type==`function`&&`__radixId`in e.type&&e.type.__radixId===Ll}function zl(e,t){let n={...t};for(let r in t){let i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?n[r]=(...e)=>{let t=a(...e);return i(...e),t}:i&&(n[r]=i):r===`style`?n[r]={...i,...a}:r===`className`&&(n[r]=[i,a].filter(Boolean).join(` `))}return{...e,...n}}function Bl(e){let t=Object.getOwnPropertyDescriptor(e.props,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var W=[`a`,`button`,`div`,`form`,`h2`,`h3`,`img`,`input`,`label`,`li`,`nav`,`ol`,`p`,`select`,`span`,`svg`,`ul`].reduce((e,t)=>{let n=Fl(`Primitive.${t}`),r=k.forwardRef((e,r)=>{let{asChild:i,...a}=e,o=i?n:t;return typeof window<`u`&&(window[Symbol.for(`radix-ui`)]=!0),(0,N.jsx)(o,{...a,ref:r})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{}),G=`Label`,K=k.forwardRef((e,t)=>(0,N.jsx)(W.label,{...e,ref:t,onMouseDown:t=>{t.target.closest(`button, input, select, textarea`)||(e.onMouseDown?.(t),!t.defaultPrevented&&t.detail>1&&t.preventDefault())}}));K.displayName=G;var q=K,J=k.forwardRef(({className:e,...t},n)=>(0,N.jsx)(q,{ref:n,className:a(`text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70`,e),...t}));J.displayName=q.displayName;var Vl=400;function Hl({...e}){return(0,N.jsx)(ce,{"data-slot":`sheet`,...e})}function Ul({...e}){return(0,N.jsx)(ie,{"data-slot":`sheet-portal`,...e})}function Wl({className:e,...t}){return(0,N.jsx)(oe,{"data-slot":`sheet-overlay`,className:a(`sheet-glass-overlay data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-[90]`,e),...t})}function Gl({className:e,children:t,side:n=`right`,showCloseButton:r=!0,resizable:i=!1,defaultWidth:o=700,minWidth:s=Vl,maxWidth:c=1600,storageKey:l=`sheet-width`,...u}){let d=`sheet-w-${l}`,[f,p]=k.useState(()=>{if(typeof window>`u`||!i)return o;let e=localStorage.getItem(d);if(e){let t=parseInt(e,10);if(!isNaN(t))return Math.max(s,Math.min(c,t))}return o}),[m,h]=k.useState(!1),g=k.useRef(null);k.useEffect(()=>{if(!i||!m)return;let e=e=>{let t=window.innerWidth,r=n===`left`?e.clientX:t-e.clientX,i=Math.min(c,t*.92),a=Math.max(s,Math.min(i,r));p(a),localStorage.setItem(d,a.toString())},t=()=>{h(!1),document.body.style.cursor=``,document.body.style.userSelect=``};return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),document.body.style.cursor=`ew-resize`,document.body.style.userSelect=`none`,()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t),document.body.style.cursor=``,document.body.style.userSelect=``}},[m,i,s,c,d,n]);let _=e=>{e.preventDefault(),h(!0)};return(0,N.jsxs)(Ul,{children:[(0,N.jsx)(Wl,{}),(0,N.jsxs)(se,{ref:g,"data-slot":`sheet-content`,style:i&&(n===`right`||n===`left`)?{width:`${f}px`,maxWidth:`92vw`}:void 0,className:a(`sheet-glass-content data-[state=open]:animate-in data-[state=closed]:animate-out fixed z-[91] flex flex-col gap-4 transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500`,n===`right`&&!i&&`data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm`,n===`right`&&i&&`data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right inset-y-0 right-0 h-full border-l`,n===`left`&&!i&&`data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm`,n===`left`&&i&&`data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left inset-y-0 left-0 h-full border-r`,n===`top`&&`data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top inset-x-0 top-0 h-auto border-b`,n===`bottom`&&`data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom inset-x-0 bottom-0 h-auto border-t`,e),...u,children:[i&&(n===`right`||n===`left`)&&(0,N.jsx)(`div`,{className:a(`absolute top-0 bottom-0 w-1 cursor-ew-resize transition-colors z-10`,n===`right`?`left-0`:`right-0`,m?`bg-blue-500 w-1`:`hover:bg-blue-400/60`),onMouseDown:_,children:(0,N.jsx)(`div`,{className:a(`absolute top-0 bottom-0 w-5`,n===`right`?`left-0 -translate-x-2`:`right-0 translate-x-2`)})}),t,r&&(0,N.jsxs)(E,{className:`ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none`,children:[(0,N.jsx)(ae,{className:`size-4`}),(0,N.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function Y({className:e,...t}){return(0,N.jsx)(`div`,{"data-slot":`sheet-header`,className:a(`sheet-glass-header flex flex-col gap-1.5 border-b p-4`,e),...t})}function Kl({className:e,...t}){return(0,N.jsx)(T,{"data-slot":`sheet-title`,className:a(`text-foreground font-semibold`,e),...t})}function ql({className:e,...t}){return(0,N.jsx)(le,{"data-slot":`sheet-description`,className:a(`text-muted-foreground text-sm`,e),...t})}function Jl({className:e,orientation:t=`horizontal`,decorative:n=!0,...r}){return(0,N.jsx)(Bo,{"data-slot":`separator`,decorative:n,orientation:t,className:a(`bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px`,e),...r})}function Yl(e=globalThis.navigator){if(!e)return!1;let t=e.userAgentData?.platform;if(t)return/macOS|iOS|iPadOS/i.test(t);let n=e.platform||``;return/Mac|iPhone|iPad|iPod/i.test(n)?!0:/Mac OS|iPhone|iPad|iPod/i.test(e.userAgent||``)}function Xl(e){return Yl(e)?`⌘+S`:`Ctrl+S`}function Zl(e){return Yl(e)?`Meta+S`:`Control+S`}function Ql(e){return Yl(e)?`⌘K`:`Ctrl+K`}function $l({className:e}){return(0,N.jsx)(`kbd`,{"aria-hidden":`true`,"data-slot":`save-shortcut`,className:a(`pointer-events-none ml-1 rounded border border-current/20 px-1 py-0.5 font-mono text-[10px] font-normal leading-none opacity-70`,e),children:Xl()})}function eu({children:e,...t}){return(0,N.jsxs)(d,{"aria-keyshortcuts":Zl(),...t,children:[e,(0,N.jsx)($l,{})]})}var tu=(0,k.createContext)(null),nu={page:100,panel:200,modal:300};function ru(e){let t=(0,k.useContext)(tu),n=(0,k.useId)();(0,k.useEffect)(()=>{if(t)return t.register(n),()=>t.unregister(n)},[n,t]),(0,k.useEffect)(()=>{t&&t.update(n,e)},[n,e,t])}function iu(){let e=Ee(),t=Te(e);return e.enabled?t?(0,N.jsxs)(fc,{variant:`outline`,children:[`AI: `,e.provider===`openai`?`OpenAI`:`Anthropic`]}):(0,N.jsx)(fc,{variant:`secondary`,children:`AI: 未配置`}):(0,N.jsx)(fc,{variant:`outline`,className:`text-xs`,children:`AI: 未启用`})}var X={theme:`system`,accentColor:`auto`,fontSize:`medium`,detailBodySizeKB:256,aiConfig:{enabled:!1,provider:`openai`,apiKey:``,baseUrl:``,model:``,models:[]},mocksFilePath:``,pluginMode:`off`,clientAliases:{}},au=null;async function ou(){try{let e=await fetch(`/api/settings`);if(e.ok){let t=await e.json(),n={...X,...t,accentColor:t.accentColor||X.accentColor,aiConfig:{...X.aiConfig,...t.aiConfig}};return au=n,we(n.aiConfig),n}}catch(e){console.error(`加载设置失败:`,e)}let e=uu();return e?(au=e,su(e).catch(console.error),e):(au={...X},au)}async function su(e){try{if((await fetch(`/api/settings`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)})).ok)au=e;else throw Error(`保存设置失败`)}catch(e){throw console.error(`保存设置失败:`,e),e}}function cu(){return au||{...X}}async function lu(e){let t=await fetch(`/api/settings`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(!t.ok)throw console.error(`保存设置失败:`,t.status),Error(`保存设置失败`);let n=await t.json().catch(()=>null);au={...X,...au||{},...n?.settings||{},...e}}function uu(){try{let e=localStorage.getItem(`theme-storage`),t=localStorage.getItem(`font-size`),n=localStorage.getItem(`meddle-ai-config`);if(!e&&!t&&!n)return null;let r={...X};if(e)try{r.theme=JSON.parse(e).theme||`system`}catch{}if(t&&(r.fontSize=t),n)try{r.aiConfig=JSON.parse(n)}catch{}return console.log(`已从 localStorage 迁移设置`),r}catch(e){return console.error(`迁移设置失败:`,e),null}}var du=k.createContext(void 0);function fu(e){if(!e)return 1;let t={small:.9,medium:1,large:1.1};if(e in t)return t[e];let n=Number(e);return!Number.isFinite(n)||n<=0?1:n>10?n/100:n}function pu(){return typeof window>`u`?`light`:window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`}function mu({children:e,defaultTheme:t=`system`}){let[n,r]=k.useState(()=>typeof window>`u`?t:cu().theme||t),[i,a]=k.useState(()=>typeof window>`u`?`auto`:cu().accentColor||`auto`),[o,s]=k.useState(!1),c=k.useRef(null),l=k.useCallback(e=>{window.document.documentElement.style.setProperty(`--app-scale`,String(e))},[]);k.useEffect(()=>{ou().then(e=>{let n=e.theme||t,i=e.accentColor||`auto`;c.current={theme:n,accentColor:i},r(n),a(i),l(fu(e.fontSize)),s(!0)}).catch(()=>{c.current={theme:t,accentColor:`auto`},s(!0)})},[t,l]);let[u,d]=k.useState(pu);k.useEffect(()=>{let e=window.matchMedia(`(prefers-color-scheme: dark)`),t=()=>d(pu());return t(),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let f=n===`system`?u:n;k.useEffect(()=>{if(!o)return;let e=window.document.documentElement;e.classList.remove(`light`,`dark`),e.classList.add(f),e.dataset.accent=i;let t=c.current;t&&t.theme===n&&t.accentColor===i||(c.current={theme:n,accentColor:i},lu({theme:n,accentColor:i}).catch(console.error))},[n,f,i,o]);let p=k.useCallback(e=>{r(e)},[]),m=k.useCallback(e=>{a(e)},[]),h=k.useCallback(()=>{r(e=>e===`light`?`dark`:e===`dark`?`system`:`light`)},[]),g=k.useMemo(()=>({theme:n,resolvedTheme:f,accentColor:i,setTheme:p,setAccentColor:m,toggleTheme:h,setZoom:l}),[n,f,i,p,m,h,l]);return(0,N.jsx)(du.Provider,{value:g,children:e})}function hu(){let e=k.useContext(du);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e}function gu(){let[e,t]=(0,k.useState)(!1),[n,r]=(0,k.useState)(!1),[i,a]=(0,k.useState)(null),[o,s]=(0,k.useState)(null),c=(0,k.useRef)(null),l=(0,k.useCallback)(async()=>{r(!0),s(null);try{let e=await fetch(`/api/sessions`,{cache:`no-store`});if(!e.ok)throw Error(`HTTP ${e.status}`);a(await e.json())}catch(e){s(e.message)}finally{r(!1)}},[]);(0,k.useEffect)(()=>{if(!e)return;l();let n=e=>{c.current&&!c.current.contains(e.target)&&t(!1)},r=e=>{e.key===`Escape`&&t(!1)};return document.addEventListener(`mousedown`,n),document.addEventListener(`keydown`,r),()=>{document.removeEventListener(`mousedown`,n),document.removeEventListener(`keydown`,r)}},[e,l]);let u=i?.current.isDefault?`Default`:i?.current.id??`Session`,f=e=>{window.open(`http://127.0.0.1:${e}/`,`_blank`,`noopener`)},p=i?.sessions.filter(e=>e.id!==i.current.id)??[];return(0,N.jsxs)(`div`,{ref:c,className:`relative`,children:[(0,N.jsxs)(d,{variant:`outline`,size:`sm`,onClick:()=>t(e=>!e),title:`切换 session`,children:[(0,N.jsx)(Nr,{"data-icon":`inline-start`}),(0,N.jsx)(`span`,{className:`hidden sm:inline`,children:u})]}),e&&(0,N.jsxs)(`div`,{className:`absolute right-0 top-full z-50 mt-1 w-80 rounded-md border bg-popover p-1 text-popover-foreground shadow-md`,children:[(0,N.jsx)(`div`,{className:`px-2 py-1.5 text-xs font-medium text-muted-foreground`,children:`当前 session`}),i&&(0,N.jsxs)(`div`,{className:`flex items-center justify-between rounded-sm px-2 py-1.5`,children:[(0,N.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,N.jsx)(y,{className:`size-3.5 text-primary shrink-0`}),(0,N.jsx)(`span`,{className:`truncate text-sm`,children:i.current.isDefault?`Default`:i.current.id})]}),(0,N.jsxs)(fc,{variant:`secondary`,className:`shrink-0`,children:[`:`,i.current.port]})]}),(0,N.jsx)(`div`,{className:`my-1 h-px bg-border`}),(0,N.jsx)(`div`,{className:`px-2 py-1.5 text-xs font-medium text-muted-foreground`,children:`其他 session`}),n&&(0,N.jsxs)(`div`,{className:`space-y-1 px-1 py-1`,children:[(0,N.jsx)(Ai,{className:`h-8 w-full`}),(0,N.jsx)(Ai,{className:`h-8 w-full`})]}),o&&(0,N.jsxs)(`div`,{className:`px-2 py-2 text-xs text-destructive`,children:[`加载失败: `,o]}),!n&&!o&&p.length===0&&(0,N.jsxs)(`div`,{className:`px-2 py-2 text-xs text-muted-foreground`,children:[`暂无其他 session。用 `,(0,N.jsx)(`code`,{className:`rounded bg-muted px-1`,children:`meddle session create`}),` 创建。`]}),!n&&!o&&p.map(e=>(0,N.jsxs)(`button`,{onClick:()=>f(e.port),className:`flex w-full items-center justify-between gap-2 rounded-sm px-2 py-1.5 text-left hover:bg-accent`,children:[(0,N.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,N.jsx)(`span`,{className:`size-2 shrink-0 rounded-full ${e.alive?`bg-green-500`:`bg-red-500`}`,title:e.alive?`running`:`orphaned`}),(0,N.jsxs)(`div`,{className:`min-w-0`,children:[(0,N.jsx)(`div`,{className:`truncate text-sm`,children:e.label||e.id}),(0,N.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:e.id})]})]}),(0,N.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:[(0,N.jsxs)(fc,{variant:`secondary`,children:[`:`,e.port]}),(0,N.jsx)(Hr,{className:`size-3.5 text-muted-foreground`})]})]},e.id))]})]})}var _u=[{tab:`logs`,path:`/logs`,label:`流量`,mode:`work`,title:`查看经过代理的本机、远程设备和插件测试流量`},{tab:`config`,path:`/config`,label:`路由规则`,mode:`config`,title:`管理代理转发规则,并在表格、文本和图表视图间切换`},{tab:`mock`,path:`/mock`,label:`Mock`,mode:`config`,title:`匹配请求后返回本地响应,用于联调和异常场景测试`},{tab:`plugins`,path:`/plugins`,label:`扩展插件`,mode:`config`,title:`控制内置、自定义和第三方插件的运行状态`},{tab:`health`,path:`/health`,label:`健康`,mode:`config`,title:`查看进程健康、连接、守护策略和日志限流状态`},{tab:`mobile`,path:`/mobile`,label:`手机代理`,mode:`config`,title:`扫码配置手机代理并安装 HTTPS 根证书`},{tab:`settings`,path:`/settings`,label:`设置`,mode:`config`,title:`管理系统偏好、配置文件和 AI 功能`}],vu={"/":`logs`,"/logs":`logs`,"/config":`config`,"/mock":`mock`,"/plugins":`plugins`,"/health":`health`,"/settings":`settings`,"/mobile":`mobile`},yu={logs:`/logs`,config:`/config`,mock:`/mock`,plugins:`/plugins`,health:`/health`,settings:`/settings`,mobile:`/mobile`};function bu(e){return vu[e]??`logs`}function xu(e){return yu[e]??`/logs`}function Su(e){return e===`logs`?`work`:`config`}var Cu=`meddle-shell-nav-collapsed`,wu=`(max-width: 1023.98px)`;function Tu(){try{return localStorage.getItem(Cu)===`1`}catch{return!1}}function Eu(e){try{localStorage.setItem(Cu,e?`1`:`0`)}catch{}}var Du={logs:qr,config:Wr,mock:Rr,plugins:ui,health:Or,mobile:fi,settings:gi};function Ou({activeTab:e,onTabChange:t,mockEnabledCount:n=0}){let[r,i]=(0,k.useState)(Tu),o=bl(wu),[s,c]=(0,k.useState)(!1),l=(0,k.useRef)(null),u=(0,k.useRef)(null),f=o&&s,p=o?!s:r,[m,h]=(0,k.useState)(o);m!==o&&(h(o),c(!1)),(0,k.useEffect)(()=>{if(!f)return;let e=l.current?.querySelector(`#app-shell-nav`);(e?.querySelector(`[aria-current="page"]`)??e?.querySelector(`[role="tab"]`))?.focus()},[f]),(0,k.useEffect)(()=>{if(!f)return;let e=e=>{let t=e.target;t&&l.current?.contains(t)||(c(!1),window.setTimeout(()=>{let e=document.activeElement;(!e||e===document.body||l.current?.contains(e))&&u.current?.focus()},0))},t=e=>{e.key===`Escape`&&(e.preventDefault(),c(!1),u.current?.focus())};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[f]);let g=()=>{if(o){c(e=>!e);return}i(e=>{let t=!e;return Eu(t),t})},_=e=>{t(e),f&&(c(!1),window.setTimeout(()=>u.current?.focus(),0))},v=t=>{let r=Du[t.tab],i=e===t.tab,o=t.tab===`mock`&&n>0,s=n>99?`99+`:String(n),c=o?`${t.label},${n} 条启用`:void 0,l=e=>(0,N.jsx)(`span`,{"data-slot":`shell-nav-mock-count`,className:`inline-block min-w-[2ch] text-center tabular-nums`,children:e}),u=(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(r,{"aria-hidden":!0}),o&&p?(0,N.jsx)(fc,{variant:`secondary`,"data-testid":`shell-nav-mock-badge`,"aria-hidden":!0,className:`pointer-events-none absolute -top-1 -right-1 h-[16px] min-w-[16px] px-1 text-[10px] leading-none`,children:l(s)}):null,(0,N.jsx)(`span`,{"data-slot":`shell-nav-label`,className:p?`sr-only`:void 0,children:t.label}),t.tab===`mock`&&!p?(0,N.jsx)(fc,{variant:`secondary`,"data-testid":o?`shell-nav-mock-badge`:`shell-nav-mock-badge-slot`,"aria-hidden":!0,className:a(`h-5 px-1.5 text-[10px]`,!o&&`invisible`),children:l(o?s:null)}):null]});return(0,N.jsxs)(Ol,{...p?{}:{open:!1},children:[(0,N.jsx)(Tl,{asChild:!0,value:t.tab,"data-testid":`shell-nav-${t.tab}`,"aria-label":c,"data-shell-nav-mode":t.mode,title:p?void 0:t.title,"aria-current":i?`page`:void 0,className:a(`relative h-auto min-h-10 w-full flex-none gap-2.5 px-3.5 py-3`,p&&`justify-center px-2.5`),children:(0,N.jsx)(kl,{describe:!1,children:u})}),(0,N.jsx)(Al,{side:`right`,sideOffset:8,"data-testid":`shell-nav-tooltip-${t.tab}`,children:t.label})]},t.tab)};return(0,N.jsx)(`div`,{ref:l,"data-testid":`app-shell-nav-rail`,"data-collapsed":p?`true`:`false`,"data-narrow":o?`true`:`false`,"data-overlay":f?`true`:`false`,className:a(`relative flex h-full min-h-0 shrink-0 flex-col self-stretch`,o?`w-14`:`w-fit`),children:(0,N.jsxs)(`div`,{"data-testid":`app-shell-nav-panel`,className:a(`flex h-full min-h-0 flex-col`,f&&`absolute inset-y-0 left-0 z-30 w-max border-r bg-background shadow-overlay-edge`),children:[(0,N.jsx)(Sl,{orientation:`vertical`,value:e,onValueChange:_,activationMode:f?`manual`:`automatic`,className:`h-full min-h-0 flex-1 flex-col`,children:(0,N.jsx)(wl,{id:`app-shell-nav`,"data-testid":`app-shell-nav`,"aria-label":`主导航`,className:a(`!h-full w-fit flex-col items-stretch justify-start gap-2.5 overflow-y-auto bg-transparent p-2.5`,p&&`w-14 overflow-x-hidden`),children:_u.map(v)})}),(0,N.jsx)(d,{ref:u,type:`button`,variant:`ghost`,size:p?`icon`:`sm`,className:a(`mt-2 mb-2.5 shrink-0`,p?`size-10 self-center`:`mx-2.5 h-10 w-auto justify-start px-3.5`),"data-testid":`shell-nav-collapse`,"aria-expanded":!p,"aria-controls":`app-shell-nav`,"aria-label":p?`展开菜单`:`收起菜单`,title:p?`展开菜单`:`收起菜单`,onClick:g,children:p?(0,N.jsx)(ai,{}):(0,N.jsx)(ii,{})})]})})}function ku({onCommandClick:e}){let{theme:t,toggleTheme:n}=hu();return(0,N.jsx)(`header`,{"data-testid":`app-shell-header`,className:`sticky top-0 z-40 border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80`,children:(0,N.jsxs)(`div`,{className:`flex h-14 w-full items-center gap-3 px-4 lg:px-6`,children:[(0,N.jsxs)(`div`,{className:`flex min-w-0 shrink-0 items-center gap-3`,children:[(0,N.jsx)(`div`,{className:`flex size-8 shrink-0 items-center justify-center rounded-lg bg-primary text-primary-foreground shadow-sm`,children:(0,N.jsx)(qr,{className:`size-4`})}),(0,N.jsxs)(`div`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,N.jsx)(`h1`,{className:`truncate text-sm font-semibold tracking-tight`,children:`Meddle`}),(0,N.jsx)(`span`,{className:`hidden text-xs text-muted-foreground xl:inline`,children:`开发代理工具`})]})]}),(0,N.jsxs)(`button`,{type:`button`,onClick:e,className:`hidden h-9 w-72 items-center gap-2 rounded-md border border-input bg-transparent px-3 text-left text-sm text-muted-foreground shadow-xs outline-none transition-colors hover:bg-muted/40 focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 sm:inline-flex`,title:`打开全局操作面板`,"data-testid":`shell-command`,children:[(0,N.jsx)(hi,{className:`size-4 shrink-0`,"aria-hidden":!0}),(0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:`搜索操作…`}),(0,N.jsx)(fc,{variant:`secondary`,children:Ql()})]}),(0,N.jsxs)(`div`,{"data-testid":`app-shell-utilities`,className:`ml-auto flex shrink-0 items-center gap-2`,children:[(0,N.jsx)(iu,{}),(0,N.jsx)(gu,{}),(0,N.jsx)(d,{variant:`ghost`,size:`icon-sm`,onClick:n,"aria-label":`当前主题: ${t},点击切换`,title:`主题: ${t===`system`?`跟随系统`:t===`light`?`浅色`:`深色`}`,children:t===`light`?(0,N.jsx)(ti,{}):t===`dark`?(0,N.jsx)(yi,{}):(0,N.jsx)(ei,{})})]})]})})}var Au=`/api/ping`,ju=2500,Mu=3e3;function Nu(){return{consecutiveFailures:0,unreachable:!1}}function Pu(e,t,n=3){if(t)return{consecutiveFailures:0,unreachable:!1};let r=e.consecutiveFailures+1;return{consecutiveFailures:r,unreachable:r>=n}}async function Fu(e={}){let t=e.path??`/api/ping`,n=e.timeoutMs??3e3,r=e.fetchImpl??fetch,i=new AbortController,a=()=>i.abort();e.signal&&(e.signal.aborted?i.abort():e.signal.addEventListener(`abort`,a,{once:!0}));let o=setTimeout(()=>i.abort(),n);try{return(await r(t,{method:`GET`,cache:`no-store`,signal:i.signal})).ok}catch{return!1}finally{clearTimeout(o),e.signal?.removeEventListener(`abort`,a)}}function Iu(e={}){let{enabled:t=!0,intervalMs:n=ju,failureThreshold:r=3,timeoutMs:i=Mu,path:a=Au,fetchImpl:o}=e,[s,c]=(0,k.useState)(Nu);return(0,k.useEffect)(()=>{if(!t)return;let e=!1,s=new AbortController,l,u=async()=>{let t=await Fu({path:a,timeoutMs:i,signal:s.signal,fetchImpl:o});e||(c(e=>Pu(e,t,r)),e||(l=setTimeout(()=>{u()},n)))};return u(),()=>{e=!0,s.abort(),l!==void 0&&clearTimeout(l)}},[t,n,i,a,o,r]),{unreachable:t?s.unreachable:!1,consecutiveFailures:t?s.consecutiveFailures:0}}var Lu=`连不上 Meddle 服务,正在重试。请确认 meddle 仍在运行`;function Ru(){let{unreachable:e}=Iu();return e?(0,N.jsx)(`div`,{role:`status`,"aria-live":`polite`,"data-testid":`backend-heartbeat-banner`,className:`shrink-0 border-b border-destructive/40 bg-destructive/10 px-4 py-2 text-sm text-destructive`,children:(0,N.jsxs)(`div`,{className:`mx-auto flex max-w-[1600px] items-center justify-center gap-2`,children:[(0,N.jsx)(Si,{className:`size-4 shrink-0`,"aria-hidden":!0}),(0,N.jsx)(`p`,{children:Lu})]})}):null}var zu=1e4;function Bu(e,t,n){if(t.length===0)return e;let r=Math.max(0,n);if(r===0)return[];let i=Math.min(t.length,r),a=Math.min(e.length,r-i),o=Array(i+a);for(let e=0;e<i;e++)o[e]=t[t.length-1-e];for(let t=0;t<a;t++)o[i+t]=e[t];return o}function Vu(e,t,n){let r=Math.max(0,n);if(r===0)return[];if(e.length===0)return t.length<=r?t:t.slice(0,r);let i=[],a=new Set,o=e=>{if(!(i.length>=r)){if(typeof e.id==`number`){if(a.has(e.id))return;a.add(e.id)}i.push(e)}};for(let t of e)o(t);for(let e of t)o(e);return i}function Hu(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.id==`number`&&typeof t.method==`string`&&typeof t.source==`string`&&typeof t.target==`string`&&typeof t.time==`string`}function Uu(e=zu){let[t,n]=(0,k.useState)([]),[r,i]=(0,k.useState)(null),[a,o]=(0,k.useState)(null),[s,c]=(0,k.useState)(!1),[l,u]=(0,k.useState)(null),d=(0,k.useRef)(e),f=(0,k.useRef)(null),p=(0,k.useRef)([]);return(0,k.useEffect)(()=>{d.current=e},[e]),(0,k.useEffect)(()=>{let e=new AbortController;return fetch(`/api/logs`,{signal:e.signal}).then(e=>e.json()).then(e=>{n(t=>Vu(t,e,d.current))}).catch(e=>{e instanceof DOMException&&e.name===`AbortError`||console.error(e)}),()=>e.abort()},[]),(0,k.useEffect)(()=>{let e=null,t=null,r=0,i=()=>{t=null;let e=p.current;e.length!==0&&(p.current=[],n(t=>Bu(t,e,d.current)))},a=()=>{t||=setTimeout(i,50)},o=()=>{let t=location.protocol===`https:`?`wss://`:`ws://`,n=new WebSocket(t+location.host+`/ws`);n.addEventListener(`message`,e=>{try{let t=JSON.parse(e.data);if(t&&t.type===`mocksUpdated`){window.dispatchEvent(new CustomEvent(`mocksUpdated`,{detail:t.rules??[]}));return}if(!Hu(t))return;p.current.push(t),a()}catch(e){console.error(`Failed to parse WebSocket message:`,e)}}),n.addEventListener(`error`,e=>{console.error(`WebSocket error:`,e)}),n.addEventListener(`close`,()=>{if(console.log(`WebSocket closed`),f.current=null,r<10){let t=Math.min(1e3*2**r,3e4);console.log(`Reconnecting in ${t}ms (attempt ${r+1}/10)`),e=setTimeout(()=>{r++,o()},t)}else console.error(`Max reconnection attempts reached`)}),n.addEventListener(`open`,()=>{console.log(`WebSocket connected`),r=0}),f.current=n};return o(),()=>{e&&clearTimeout(e),t&&clearTimeout(t),p.current=[],f.current&&=(f.current.close(),null)}},[]),{records:t,selectedRecordId:r,recordDetail:a,detailLoading:s,detailError:l,fetchDetail:(0,k.useCallback)(async e=>{i(e),c(!0),o(null),u(null);try{let t=await fetch(`/api/logs/${e}`),n=await t.json();if(!t.ok)throw Error(n?.error||`加载详情失败 (${t.status})`);o(n)}catch(e){u(e instanceof Error?e.message:`加载详情失败`),console.error(`Failed to fetch detail:`,e)}finally{c(!1)}},[]),closeDetail:(0,k.useCallback)(()=>{i(null),o(null)},[]),clearRecords:(0,k.useCallback)(()=>{p.current=[],n([])},[]),replayRequest:(0,k.useCallback)(async e=>{let t=await(await fetch(`/api/replay/${e}`,{method:`POST`})).json();if(t.status===`success`)return t;throw Error(t.error||`重放请求失败`)},[])}}var Wu=/^(?:\d{1,3}\.){3}\d{1,3}$/,Z=/^(?:[0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}(?:%[\w.-]+)?$/,Gu=/^[A-Za-z0-9_.-]+$/;function Ku(e){return Wu.test(e)||Z.test(e)}function qu(e){return e.includes(`:`)&&!e.startsWith(`[`)?`[${e}]`:e}function Ju(e){let t=e.indexOf(`#`);return(t>=0?e.slice(0,t):e).trim()}function Yu(e){let t=Ju(e);if(!t)return null;let[n,...r]=t.split(/\s+/).filter(Boolean);return!n||r.length===0||!Ku(n)||!r.every(e=>Gu.test(e))?null:`${r.join(` `)} ${qu(n)}`}function Xu(e){let t=!1,n=e.split(/\r?\n/).map(e=>{let n=Yu(e);return n?(t=!0,n):e}).join(`
|
|
17
|
+
`);return t?n:e}function Zu(e){return e.split(/\r?\n/).flatMap((e,t)=>{let n=e.trim();return!n||n.startsWith(`#`)||(n.startsWith(`//`)?n.slice(2).trim():n).split(/\s+/).filter(Boolean).filter(e=>!e.startsWith(`!`)).length>=2?[]:[{line:t+1,content:e}]})}function Qu(e){return e.split(/\r?\n/).filter(e=>e.trim()).flatMap(e=>{let t=e.trim();if(t.startsWith(`#`))return[];let n=!0;t.startsWith(`//`)?(n=!1,e=t.slice(2).trim()):e=t;let r=e.split(/\s+/).filter(Boolean);if(r.length<2)return[];let i=[],a=r.filter(e=>e.startsWith(`!`)?(i.push(e.slice(1)),!1):!0);if(a.length<2)return[];let o=a[a.length-1];return a.slice(0,-1).map(e=>({rule:e,target:o,enabled:n,exclusions:[...i]}))})}function $u(e){return e.map(e=>{let t=e.enabled?``:`//`,n=(e.exclusions||[]).map(e=>`!${e}`).join(` `);return`${t}${(n?[e.rule,n,e.target]:[e.rule,e.target]).join(` `)}`}).join(`
|
|
18
|
+
`)}var ed=`该行剩余的 pattern 以 // 或 # 开头,拆开后会被当成注释,请用文本编辑器手动修改`,td=class extends Error{code=`RULE_LINE_SPLIT_UNSAFE`;constructor(){super(ed),this.name=`RuleLineSplitError`}},nd=`规则不能以 // 或 # 开头,否则会被当成禁用行或注释。要写注释或禁用规则,请用文本编辑器。`,rd=class extends Error{code=`RULE_LINE_SPLIT_UNSAFE`;constructor(){super(nd),this.name=`RuleNewRuleCommentError`}};function id(e){return e.enabled&&(e.rule.startsWith(`//`)||e.rule.startsWith(`#`))}function ad(e,t){if(id(e))throw t.has(e.rule)?new td:new rd;return $u([e])}function od(e,t){let n=e.exclusions||[],r=t.exclusions||[];return e.enabled===t.enabled&&e.rule===t.rule&&e.target===t.target&&n.length===r.length&&n.every((e,t)=>e===r[t])}function sd(e,t){let n=e.length,r=t.length,i=Array(n).fill(-1),a=Array(r).fill(-1);if(n===0||r===0)return{matchA:i,matchB:a};if((n+1)*(r+1)>4e6){let o=0;for(let s=0;s<r&&o<n;s++)for(let r=o;r<n;r++)if(od(e[r],t[s])){i[r]=s,a[s]=r,o=r+1;break}return{matchA:i,matchB:a}}let o=r+1,s=new Int32Array((n+1)*o);for(let i=n-1;i>=0;i--)for(let n=r-1;n>=0;n--)s[i*o+n]=od(e[i],t[n])?s[(i+1)*o+n+1]+1:Math.max(s[(i+1)*o+n],s[i*o+n+1]);let c=0,l=0;for(;c<n&&l<r;)od(e[c],t[l])?(i[c]=l,a[l]=c,c++,l++):s[(c+1)*o+l]>=s[c*o+l+1]?c++:l++;return{matchA:i,matchB:a}}function cd(e,t){if(t.startsWith(``))return``+cd(e,t.slice(1));if(!t){if(e.some(id))throw new rd;return $u(e)}let n=t.includes(`\r
|
|
19
19
|
`)?`\r
|
|
20
20
|
`:`
|
|
21
|
-
`,r=t.split(/\r?\n/).map(e=>{let t=Zu(e);return{raw:e,items:t.length>0?t:null}}),i=[],a=[];r.forEach((e,t)=>{e.items?.forEach((e,n)=>{i.push({entry:t,k:n}),a.push(e)})});let{matchA:o,matchB:s}=od(a,e),c=new Set(a.map(e=>e.rule)),l=Array(r.length).fill(-1);i.forEach((e,t)=>{l[e.entry]<0&&(l[e.entry]=t)});let u=r.map((e,t)=>{if(!e.items)return!1;let n=l[t],r=o[n];return r<0?!1:e.items.every((e,t)=>o[n+t]===r+t)}),d=r.map((e,t)=>e.items?e.items.filter((e,n)=>o[l[t]+n]<0).length:0),f=Array(e.length+1).fill(r.length);for(let t=e.length-1;t>=0;t--)f[t]=s[t]>=0?i[s[t]].entry:f[t+1];let p=r.length;for(;p>0&&!r[p-1].raw.trim();)p--;let m=[],h=0,g=e=>{for(;h<e;h++)r[h].items||m.push(r[h].raw)},_=0;for(;_<e.length;){let t=s[_];if(t>=0){let{entry:n,k:a}=i[t];g(n);let o=r[n].items;if(u[n]&&a===0){m.push(r[n].raw),_+=o.length,h=n+1;continue}m.push(id(e[_],c)),_++;continue}let n=f[_+1],a=!1;for(let e=h;e<n;e++)if(r[e].items&&d[e]>0){g(e),d[e]--,a=!0;break}!a&&n===r.length&&g(p),m.push(id(e[_],c)),_++}return g(r.length),m.join(n)}var cd=`X-Meddle-UI-Token`,ld=`meddle-ui-token`,ud=null;function dd(){if(typeof document>`u`)return null;let e=document.querySelector(`meta[name="${ld}"]`)?.getAttribute(`content`);return e&&e.trim()?e.trim():null}async function fd(){try{let e=await fetch(`/api/ui-token`,{cache:`no-store`,credentials:`same-origin`});if(!e.ok)return null;let t=await e.json();return typeof t.token==`string`&&t.token?t.token:null}catch{return null}}async function pd(e=!1){return!e&&(ud||=dd(),ud)||(ud=await fd()),ud}async function md(e,t){for(let n=0;n<2;n+=1){let r=await pd(n>0);try{let i=await fetch(`/api/rule-files/${encodeURIComponent(e)}/readonly`,{method:`PUT`,credentials:`same-origin`,headers:{"Content-Type":`application/json`,...r?{[cd]:r}:{}},body:JSON.stringify({readonly:t})}),a=await i.json().catch(()=>null);if(i.ok&&a?.status===`success`)return{success:!0};if(i.status===403&&a?.code===`UI_TOKEN_INVALID`&&n===0)continue;return{success:!1,error:a?.error||`保存失败(${i.status})`}}catch(e){return{success:!1,error:e instanceof Error?e.message:`保存失败`}}}return{success:!1,error:`保存失败`}}function hd(){let[e,t]=(0,k.useState)([]),[n,r]=(0,k.useState)([]),[i,a]=(0,k.useState)(null),o=(0,k.useRef)(new Map),s=(0,k.useCallback)(async()=>{try{let e=await(await fetch(`/api/rule-files`)).json(),t=Array.isArray(e)?e:[];return r(t),t}catch(e){return console.error(`Failed to fetch rule files:`,e),[]}},[]),c=(0,k.useCallback)(async e=>{let t=await fetch(`/api/rule-files/${encodeURIComponent(e)}/content`);return new TextDecoder(`utf-8`,{ignoreBOM:!0}).decode(await t.arrayBuffer())},[]),l=(0,k.useCallback)(async e=>{try{let n=await c(e);o.current.set(e,n),t(Zu(n)),a(e)}catch(e){console.error(`Failed to fetch file content:`,e)}},[c]),u=(0,k.useCallback)(async(e,t)=>{try{let n=await(await fetch(`/api/rule-files/${encodeURIComponent(e)}/content`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({content:t})})).json();return n.status===`success`&&o.current.set(e,t),n.status===`success`}catch(e){return console.error(`Failed to save file content:`,e),!1}},[]);return{rules:e,setRules:t,ruleFiles:n,activeFileName:i,fetchRuleFiles:s,fetchFileContent:l,fetchRuleFileRawContent:c,saveRuleFileRawContent:u,saveFileContent:(0,k.useCallback)(async(e,t)=>u(e,sd(t,o.current.get(e)??``)),[u]),createRuleFile:(0,k.useCallback)(async(e,t=``)=>{let n=e.trim();try{let e=await(await fetch(`/api/rule-files`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:n,content:t,enabled:!0})})).json();return e.status===`success`?(await s(),{success:!0}):{success:!1,error:e.error}}catch(e){return(await s()).some(e=>e.name===n)?{success:!0}:{success:!1,error:e instanceof Error?e.message:`创建规则文件失败`}}},[s]),toggleRuleFile:(0,k.useCallback)(async(e,t)=>{try{return(await(await fetch(`/api/rule-files/${encodeURIComponent(e)}`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({enabled:t})})).json()).status===`success`?(await s(),!0):!1}catch(e){return console.error(`Failed to toggle rule file:`,e),!1}},[s]),renameRuleFile:(0,k.useCallback)(async(e,t)=>{let n=t.trim();if(!n)return{success:!1,error:`规则文件名称不能为空`};try{let t=await(await fetch(`/api/rule-files/${encodeURIComponent(e)}`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({newName:n})})).json();if(t.status!==`success`)return{success:!1,error:t.error||`重命名失败`};let r=typeof t.name==`string`?t.name:n;if(r!==e){let t=o.current.get(e);t!==void 0&&o.current.set(r,t),o.current.delete(e)}return i===e&&a(r),await s(),{success:!0,name:r}}catch(e){return{success:!1,error:e instanceof Error?e.message:`重命名失败`}}},[i,s]),deleteRuleFile:(0,k.useCallback)(async e=>{try{return(await(await fetch(`/api/rule-files/${encodeURIComponent(e)}`,{method:`DELETE`})).json()).status===`success`?(i===e&&(a(null),t([])),await s(),!0):!1}catch(e){return console.error(`Failed to delete rule file:`,e),!1}},[s,i]),reorderRuleFiles:(0,k.useCallback)(async e=>{let t=n,i=new Map(t.map(e=>[e.name,e])),a=e.map(e=>i.get(e)).filter(e=>!!e);a.length===e.length&&r(a);try{return(await(await fetch(`/api/rule-files/order`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({order:e})})).json()).status===`success`?(await s(),!0):(r(t),await s(),!1)}catch(e){return console.error(`Failed to reorder rule files:`,e),r(t),await s(),!1}},[s,n]),setRuleFileReadonly:(0,k.useCallback)(async(e,t)=>{let n=await md(e,t);return n.success&&(r(n=>n.map(n=>n.name===e?{...n,readonly:t}:n)),s()),n},[s])}}var gd=`mocksUpdated`,_d=!1;function vd(){let e=_d;return _d=!1,e}function yd(e,t={}){let n=e;n?.code===`MOCKS_FILE_INVALID`&&(_d=!0,t.silent||De.error(n.error||`Mock 文件格式错误`),window.dispatchEvent(new CustomEvent(Ae)))}function Q(e,t){return e.some(e=>e.id===t.id)?xd(e,t):e}function bd(e){let t=new Map;for(let n of e)t.set(n.id,n);return Array.from(t.values()).sort((e,t)=>e.id-t.id)}function xd(e,t){return bd([...e.filter(e=>e.id!==t.id),t])}function Sd(){let[e,t]=(0,k.useState)([]),n=(0,k.useCallback)(async()=>{try{let e=await(await fetch(`/api/mocks`,{cache:`no-store`})).json();t(bd(Array.isArray(e)?e:[]))}catch(e){console.error(`Failed to fetch mocks:`,e)}},[]);return(0,k.useEffect)(()=>{n()},[n]),(0,k.useEffect)(()=>{let e=e=>{let n=e;t(bd(Array.isArray(n.detail)?n.detail:[]))};return window.addEventListener(gd,e),()=>window.removeEventListener(gd,e)},[]),{mockRules:e,fetchMocks:n,createMock:(0,k.useCallback)(async(e,n)=>{try{let r=await(await fetch(`/api/mocks`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)})).json();return r.status===`success`?(t(e=>xd(e,r.rule)),r.rule):(yd(r,{silent:n?.silentInvalid}),null)}catch(e){return console.error(`Failed to create mock:`,e),null}},[]),updateMock:(0,k.useCallback)(async(e,n,r)=>{let i;t(t=>(i=t.find(t=>t.id===e),i?xd(t,{...i,...n}):t));try{let a=await(await fetch(`/api/mocks/${e}`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)})).json();if(a.status===`success`)return t(e=>xd(e,a.rule)),!0;if(yd(a,{silent:r?.silentInvalid}),i){let e=i;t(t=>Q(t,e))}return!1}catch(e){if(console.error(`Failed to update mock:`,e),i){let e=i;t(t=>Q(t,e))}return!1}},[]),deleteMock:(0,k.useCallback)(async e=>{try{let n=await(await fetch(`/api/mocks/${e}`,{method:`DELETE`})).json();return n.status===`success`?(t(t=>t.filter(t=>t.id!==e)),!0):(yd(n),!1)}catch(e){return console.error(`Failed to delete mock:`,e),!1}},[])}}function Cd(){return!1}function wd(){let[e,t]=(0,k.useState)([]),[n,r]=(0,k.useState)(`off`),[i,a]=(0,k.useState)([]),[o,s]=(0,k.useState)({allowAll:!1,trusted:[]}),c=(0,k.useCallback)(async()=>{try{let e=await(await fetch(`/api/plugins`)).json();r(e.mode||`off`),t(e.plugins||[])}catch(e){console.error(`Failed to fetch plugins:`,e)}},[]);return{plugins:e,pluginMode:n,switchPluginMode:(0,k.useCallback)(async e=>{try{(await fetch(`/api/pipeline/mode`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({mode:e})})).ok&&r(e)}catch(e){console.error(`Failed to switch plugin mode:`,e)}},[]),thirdPartyPlugins:i,thirdPartySecurity:o,fetchPlugins:c,startPlugin:(0,k.useCallback)(async e=>{try{await fetch(`/api/plugins/${e}/start`,{method:`POST`})}catch(e){console.error(`Failed to start plugin:`,e)}},[]),stopPlugin:(0,k.useCallback)(async e=>{try{await fetch(`/api/plugins/${e}/stop`,{method:`POST`})}catch(e){console.error(`Failed to stop plugin:`,e)}},[]),togglePlugin:(0,k.useCallback)(async(e,n)=>{try{(await fetch(`/api/plugins/${encodeURIComponent(e)}/toggle`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({enabled:n})})).ok&&t(t=>t.map(t=>t.id===e?{...t,state:n?`running`:`disabled`}:t))}catch(e){console.error(`Failed to toggle plugin:`,e)}},[]),fetchThirdPartyPlugins:(0,k.useCallback)(async()=>{if(Cd())try{let e=await fetch(`/api/plugins/third-party`),t=e.headers.get(`content-type`)||``;if(!e.ok||!t.includes(`application/json`)){a([]),s({allowAll:!1,trusted:[]});return}let n=await e.json();a(n.plugins||[]),s(n.security||{allowAll:!1,trusted:[]})}catch(e){console.error(`Failed to fetch third-party plugins:`,e)}},[]),loadThirdPartyPlugin:(0,k.useCallback)(async e=>{if(Cd())try{await fetch(`/api/plugins/third-party/load`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({path:e})})}catch(e){console.error(`Failed to load third-party plugin:`,e)}},[]),unloadThirdPartyPlugin:(0,k.useCallback)(async e=>{if(Cd())try{await fetch(`/api/plugins/third-party/${e}/unload`,{method:`POST`})}catch(e){console.error(`Failed to unload third-party plugin:`,e)}},[])}}function Td(){let[e,t]=(0,k.useState)(Ru),n=Hu(e),r=hd(),i=Sd(),a=wd();return{records:n.records,selectedRecordId:n.selectedRecordId,recordDetail:n.recordDetail,detailLoading:n.detailLoading,detailError:n.detailError,fetchDetail:n.fetchDetail,closeDetail:n.closeDetail,clearRecords:n.clearRecords,replayRequest:n.replayRequest,maxRecords:e,setMaxRecords:t,rules:r.rules,setRules:r.setRules,ruleFiles:r.ruleFiles,activeFileName:r.activeFileName,fetchRuleFiles:r.fetchRuleFiles,fetchFileContent:r.fetchFileContent,fetchRuleFileRawContent:r.fetchRuleFileRawContent,saveRuleFileRawContent:r.saveRuleFileRawContent,saveFileContent:r.saveFileContent,createRuleFile:r.createRuleFile,toggleRuleFile:r.toggleRuleFile,renameRuleFile:r.renameRuleFile,deleteRuleFile:r.deleteRuleFile,reorderRuleFiles:r.reorderRuleFiles,setRuleFileReadonly:r.setRuleFileReadonly,mockRules:i.mockRules,fetchMocks:i.fetchMocks,createMock:i.createMock,updateMock:i.updateMock,deleteMock:i.deleteMock,plugins:a.plugins,pluginMode:a.pluginMode,switchPluginMode:a.switchPluginMode,thirdPartyPlugins:a.thirdPartyPlugins,thirdPartySecurity:a.thirdPartySecurity,fetchPlugins:a.fetchPlugins,startPlugin:a.startPlugin,stopPlugin:a.stopPlugin,togglePlugin:a.togglePlugin,fetchThirdPartyPlugins:a.fetchThirdPartyPlugins,loadThirdPartyPlugin:a.loadThirdPartyPlugin,unloadThirdPartyPlugin:a.unloadThirdPartyPlugin}}function Ed(e){let t=typeof e.source==`string`?e.source:``,n=typeof e.method==`string`?e.method:``,r=t.toLowerCase(),i=n.toUpperCase();if(!r)return`other`;if(r.startsWith(`ws://`)||r.startsWith(`wss://`))return`websocket`;if(i!==`GET`||r.includes(`/api/`)||r.includes(`.json`))return`fetch`;let a=r.split(`?`)[0].split(`#`)[0].split(`/`),o=a[a.length-1]||``,s=o.includes(`.`)&&o.split(`.`).pop()||``;return[`html`,`htm`,`php`,`asp`,`aspx`,`jsp`].includes(s)||!s&&i===`GET`?`doc`:s===`css`?`css`:[`js`,`mjs`,`jsx`,`ts`,`tsx`].includes(s)?`js`:[`woff`,`woff2`,`ttf`,`otf`,`eot`].includes(s)?`font`:[`png`,`jpg`,`jpeg`,`gif`,`svg`,`webp`,`ico`,`bmp`].includes(s)?`img`:[`mp4`,`webm`,`ogg`,`mp3`,`wav`,`flac`,`aac`,`m4a`].includes(s)?`media`:[`manifest`,`webmanifest`].includes(s)?`manifest`:s===`wasm`?`wasm`:`other`}var Dd=new WeakMap;function Od(e){let t=Dd.get(e);if(t)return t;let n=typeof e.method==`string`?e.method:``,r=typeof e.source==`string`?e.source:``,i=typeof e.target==`string`?e.target:``,a=typeof e.time==`string`?e.time:``,o=e.clientType||``,s=e.clientIp||``,c=e.clientName||``,l=e.applicationName||``,u=e.applicationProcess||``,d=e.applicationBundleId||``,f=e.applicationPid?.toString()||``,p=e.applicationIdentitySource||``,m=e.applicationIdentityConfidence||``,h=r;try{h=new URL(r).hostname}catch{}let g={methodUpper:n.toUpperCase(),statusCode:e.statusCode,statusText:e.statusCode?.toString()||``,sourceLower:r.toLowerCase(),domainLower:h.toLowerCase(),clientLower:`${o} ${c} ${s}`.toLowerCase(),clientIpLower:s.toLowerCase(),applicationLower:`${l} ${u} ${d} ${f} ${p} ${m}`.toLowerCase(),haystack:`${n} ${r} ${i} ${a} ${o} ${s} ${c} ${l} ${u} ${d} ${f} ${p} ${m}`.toLowerCase(),resourceType:Ed(e)};return Dd.set(e,g),g}function kd(e){let[t,n]=(0,k.useState)(``),[r,i]=(0,k.useState)(`all`),[a,o]=(0,k.useState)(`all`),s=(0,k.useDeferredValue)(t);return{filterText:t,setFilterText:n,resourceTypeFilter:r,setResourceTypeFilter:i,clientSourceFilter:a,setClientSourceFilter:o,filteredRecords:(0,k.useMemo)(()=>{let t=s.trim();if(!t&&r===`all`&&a===`all`)return e;let n=t.split(/\s+/).filter(Boolean),i=[];for(let t of e){if(a!==`all`&&t.clientType!==a)continue;let e=Od(t);r!==`all`&&e.resourceType!==r||n.every(t=>{let n=t.startsWith(`-`)&&t.length>1,r=n?t.slice(1):t,i=r.toLowerCase(),a=!1;if(i.startsWith(`method:`))a=e.methodUpper===r.slice(7).toUpperCase();else if(i.startsWith(`status:`)){let t=i.slice(7);if(!e.statusCode)a=!1;else if(t.includes(`x`)){let n=t.replace(/x/gi,``);a=e.statusText.startsWith(n)}else a=e.statusText===t}else a=i.startsWith(`domain:`)?e.domainLower.includes(i.slice(7))||e.sourceLower.includes(i.slice(7)):i.startsWith(`client:`)?e.clientLower.includes(i.slice(7)):i.startsWith(`ip:`)?e.clientIpLower.includes(i.slice(3)):i.startsWith(`app:`)?e.applicationLower.includes(i.slice(4)):Ad(i,e.haystack);return n?!a:a})&&i.push(t)}return i},[e,s,r,a])}}function Ad(e,t){if(t.includes(e))return!0;let n=0;for(let r=0;r<t.length&&n<e.length;r++)e[n]===t[r]&&n++;return n===e.length}var jd=[`content-length`,`content-encoding`,`connection`,`date`,`etag`,`last-modified`,`server`];function Md(e){if(!e)return{};let t={};return Object.entries(e).forEach(([e,n])=>{jd.includes(e.toLowerCase())||(t[e]=n)}),t}function $(e){let t=e.match(/^\(truncated, \d+ bytes\)\n/);return t?e.substring(t[0].length):e}function Nd(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Pd(e){let t=Md(e.responseHeaders),n=$(e.responseBody);return{urlPattern:Nd(e.source),body:n,statusCode:e.statusCode,headers:t,name:`从日志创建`,method:`*`,enabled:!0}}var Fd=`mock-config:open-create`,Id=(0,k.createContext)(null);function Ld(e){(0,k.useEffect)(()=>{let t=t=>{t.isComposing||t.key.toLowerCase()===`k`&&(t.metaKey||t.ctrlKey)&&(t.preventDefault(),e())};return window.addEventListener(`keydown`,t,{capture:!0}),()=>window.removeEventListener(`keydown`,t,{capture:!0})},[e])}var Rd=(0,k.lazy)(()=>ze(()=>import(`./global-panel-shell-NaUhzX7J.js`).then(e=>({default:e.GlobalPanelShell})),__vite__mapDeps([0,1,2,3,4,5,6,7,8]))),zd=class extends k.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error(`Global panel failed to render`,e,t)}render(){return this.state.error?(0,N.jsx)(`div`,{className:`fixed inset-0 z-[82] flex items-center justify-center bg-background/80 p-6 backdrop-blur-sm`,children:(0,N.jsxs)(`div`,{className:`w-full max-w-lg rounded-lg border bg-card p-5 shadow-xl`,children:[(0,N.jsx)(`h2`,{className:`font-semibold`,children:`面板加载失败`}),(0,N.jsx)(`p`,{className:`mt-2 break-words text-sm text-destructive`,children:this.state.error.message}),(0,N.jsx)(`button`,{type:`button`,className:`mt-4 rounded-md border px-3 py-1.5 text-sm`,onClick:this.props.onClose,children:`关闭面板`})]})}):this.props.children}};function Bd({children:e,commands:t,renderPanel:n}){let[r,i]=(0,k.useState)(!1),[a,o]=(0,k.useState)([]),s=(0,k.useCallback)(()=>{o([]),i(!0)},[]),c=(0,k.useCallback)(e=>{o([e]),i(!0)},[]),l=(0,k.useCallback)(e=>{o(t=>[...t,e]),i(!0)},[]),u=(0,k.useCallback)(()=>{o(e=>e.slice(0,-1))},[]),d=(0,k.useCallback)(()=>{i(!1),o([])},[]);Ld(s),(0,k.useEffect)(()=>{let e=()=>s(),t=e=>{let t=e.detail;t?.id&&c(t)};return window.addEventListener(`global-panel:open-command`,e),window.addEventListener(`global-panel:open-panel`,t),()=>{window.removeEventListener(`global-panel:open-command`,e),window.removeEventListener(`global-panel:open-panel`,t)}},[s,c]);let f=a.length>0?a[a.length-1]:null,p=(0,k.useMemo)(()=>({open:r,stack:a,currentRoute:f,openCommand:s,openPanel:c,pushPanel:l,back:u,close:d}),[u,d,f,r,s,c,l,a]),m=typeof t==`function`?t(p):t;return(0,N.jsxs)(Id.Provider,{value:p,children:[e,r&&(0,N.jsx)(zd,{onClose:d,children:(0,N.jsx)(k.Suspense,{fallback:null,children:(0,N.jsx)(Rd,{commands:m,renderPanel:e=>n(e,p)})})},f?.id||`command`)]})}function Vd(e){return`local.${e.replace(/\.js$/,``)}`}function Hd(e,t,n=new Set){let r=new Set,i=t.map(t=>{let n=e.find(e=>e.filename===t.filename)??(t.pluginId?e.find(e=>e.id===t.pluginId):void 0)??e.find(e=>e.id===Vd(t.filename)&&e.source!==`builtin`&&(!e.filename||e.filename===t.filename));return n&&r.add(n.id),{filename:t.filename,file:t,pluginId:n?.id??t.pluginId??Vd(t.filename),loadedPlugin:n,fileDeleted:!1}});for(let t of e)r.has(t.id)||n.has(t.id)||!Ud(t)||(r.add(t.id),i.push({filename:Wd(t)||t.id,pluginId:t.id,loadedPlugin:t,fileDeleted:!0}));return{builtinPlugins:e.filter(e=>r.has(e.id)||n.has(e.id)?!1:e.source?e.source===`builtin`:!e.id.startsWith(`local.`)),customRows:i}}function Ud(e){return e.source?e.source===`custom`:e.id.startsWith(`local.`)}function Wd(e){return e.filename?e.filename:e.id.startsWith(`local.`)?`${e.id.slice(6)}.js`:``}var Gd=(0,k.lazy)(()=>ze(()=>import(`./rule-config-Dw9pcuah.js`).then(e=>({default:e.RuleConfig})),__vite__mapDeps([9,1,10,2,5,11,12,6,13,3,4,14,15,16,17,18,19,20,21]))),Kd=(0,k.lazy)(()=>ze(()=>import(`./mock-config-TPmfJwAt.js`).then(e=>({default:e.MockConfig})),__vite__mapDeps([22,1,10,2,5,11,23,12,6,13,4,24,14,16,25,26,27,17,28,8,20,29,18,19]))),qd=(0,k.lazy)(()=>ze(()=>import(`./plugin-config-DsX9xCW_.js`).then(e=>({default:e.PluginConfig})),__vite__mapDeps([30,1,10,2,5,11,4,31,32,33,25,17,18]))),Jd=(0,k.lazy)(()=>ze(()=>import(`./detail-panel-BtgWWeu3.js`).then(e=>({default:e.DetailPanel})),__vite__mapDeps([34,1,2,4,5,35,36,13,37,38,39,40,41,27,16,20,42]))),Yd=(0,k.lazy)(()=>ze(()=>import(`./settings-panel-D8DEH8aH.js`).then(e=>({default:e.SettingsPanel})),__vite__mapDeps([43,1,10,2,5,11,4,31,13,7,38,14,32,44,45,16,29,17,46,28,8]))),Xd=(0,k.lazy)(()=>ze(()=>import(`./plugin-generator-Bj4f6dxo.js`).then(e=>({default:e.PluginGenerator})),__vite__mapDeps([47,1,2,4,5,13,38,24,40,27,16,25,17,48,49,8]))),Zd=(0,k.lazy)(()=>ze(()=>import(`./plugin-code-editor--Gf4ZwGb.js`).then(e=>({default:e.PluginCodeEditor})),__vite__mapDeps([50,1,23,2,4,5,51,44,33,16,25,17,48,49,8]))),Qd=(0,k.lazy)(()=>ze(()=>import(`./plugin-test-dialog-DICuykBK.js`).then(e=>({default:e.PluginTestDialog})),__vite__mapDeps([52,1,23,2,4,5,35,36,7,38,51,32,27,25,48,49,8]))),$d=(0,k.lazy)(()=>ze(()=>import(`./rule-ai-assistant-panel-BEfPNBbx.js`).then(e=>({default:e.RuleAiAssistantPanel})),__vite__mapDeps([53,1,27,46,49,8]))),ef=(0,k.lazy)(()=>ze(()=>import(`./mock-editor-panel-WQwcHSTD.js`).then(e=>({default:e.MockEditorPanel})),__vite__mapDeps([26,1,10,2,5,11,23,12,6,13,4,24,14,27,16,25,17,28,8,20]))),tf=(0,k.lazy)(()=>ze(()=>import(`./route-preview-C-LzS1lT.js`).then(e=>({default:e.RoutePreview})),__vite__mapDeps([54,1,36]))),nf=(0,k.lazy)(()=>ze(()=>import(`./rule-overview-panel-C4QQ7U3S.js`).then(e=>({default:e.RuleOverviewPanel})),__vite__mapDeps([55,1,2,32,15,19]))),rf=(0,k.lazy)(()=>ze(()=>import(`./mobile-proxy-panel-BY8Oi-qC.js`).then(e=>({default:e.MobileProxyPanel})),__vite__mapDeps([56,1,2,13,40,32,41,45,57,16,46,42]))),af=(0,k.lazy)(()=>ze(()=>import(`./health-panel-DhXLqcOU.js`).then(e=>({default:e.HealthPanel})),__vite__mapDeps([58,1,2,31,11,38,39,32,41,57,46,19])));function of(){return(0,N.jsxs)(`div`,{className:`flex flex-col gap-3 p-6`,"aria-label":`加载中`,children:[(0,N.jsx)(Ai,{className:`h-5 w-32`}),(0,N.jsx)(Ai,{className:`h-9 w-full`}),(0,N.jsx)(Ai,{className:`h-64 w-full`})]})}function sf(){let e=Td(),t=e.fetchPlugins,n=Zt(),r=Jt(),{filterText:i,setFilterText:a,resourceTypeFilter:o,setResourceTypeFilter:s,clientSourceFilter:c,setClientSourceFilter:l,filteredRecords:u}=kd(e.records),[d,f]=(0,k.useState)(!0),[p,m]=(0,k.useState)(!0),h=yu(r.pathname),g=xu(h),_=bl(`(max-width: 900px)`),v=e=>{n(bu(e))},y=(0,k.useCallback)(t=>{e.closeDetail(),n(`/config`),window.setTimeout(()=>{window.dispatchEvent(new CustomEvent(`route-rule:highlight`,{detail:{pattern:t.source,target:t.target}}))},120)},[n,e]),b=(0,k.useCallback)(t=>{let r=Pd(t);e.closeDetail(),n(`/mock`),window.setTimeout(()=>{window.dispatchEvent(new CustomEvent(Fd,{detail:{initialData:r}}))},120)},[n,e]),x=(0,k.useCallback)(async t=>{let n=await e.replayRequest(t);return e.fetchDetail(n.recordId),n},[e]),C=(0,k.useCallback)(()=>{window.dispatchEvent(new CustomEvent(`global-panel:open-command`))},[]),ee=(0,k.useCallback)(e=>{window.dispatchEvent(new CustomEvent(`global-panel:open-panel`,{detail:e}))},[]),te=(0,k.useCallback)(t=>{if(e.selectedRecordId===t){e.closeDetail();return}e.fetchDetail(t),_&&ee({id:`request.detail`,title:`请求详情`,size:`lg`})},[_,ee,e]),ne=(0,k.useCallback)(t=>[{id:`nav.logs`,title:`打开日志`,section:`导航`,icon:qr,keywords:[`logs`,`请求`],run:()=>n(`/logs`)},{id:`nav.rules`,title:`打开路由规则`,section:`导航`,icon:Wr,keywords:[`rules`,`config`],run:()=>n(`/config`)},{id:`nav.mock`,title:`打开 Mock`,section:`导航`,icon:Rr,keywords:[`mock`],run:()=>n(`/mock`)},{id:`nav.plugins`,title:`打开扩展插件`,section:`导航`,icon:ui,keywords:[`plugin`,`plugins`],run:()=>n(`/plugins`)},{id:`nav.health`,title:`打开运行健康`,section:`导航`,icon:Or,keywords:[`health`,`健康`,`watchdog`,`运行状态`],run:()=>n(`/health`)},{id:`panel.settings`,title:`打开系统设置`,description:`偏好、配置文件、AI 配置`,section:`全局`,icon:gi,keywords:[`settings`,`配置`,`AI`],closeOnRun:!1,run:()=>t.openPanel({id:`settings`,title:`系统设置`,description:`管理系统偏好、配置和 AI 功能`,size:`lg`})},{id:`panel.mobile-proxy`,title:`打开手机代理二维码`,description:`扫码配置手机代理并安装 HTTPS 根证书`,section:`全局`,icon:fi,keywords:[`手机`,`二维码`,`QR`,`remote`,`proxy`],closeOnRun:!1,run:()=>t.openPanel({id:`mobile-proxy`,title:`手机代理`,description:`扫描二维码,在手机上配置代理与 HTTPS 证书`,size:`md`})},{id:`logs.focus-filter`,title:`聚焦日志过滤器`,description:`输入 method:GET、domain:example.com 或关键词筛选请求`,section:`日志`,icon:hi,run:()=>{n(`/logs`),window.setTimeout(()=>document.getElementById(`proxy-log-filter`)?.focus(),50)}},{id:`logs.toggle-recording`,title:d?`暂停记录日志`:`恢复记录日志`,section:`日志`,icon:d?si:li,run:()=>f(e=>!e)},{id:`logs.clear`,title:`清空日志`,section:`日志`,icon:S,danger:!0,confirm:`确定要清空当前日志列表吗?`,run:e.clearRecords},{id:`logs.toggle-auto-scroll`,title:p?`关闭自动滚动`:`开启自动滚动`,section:`日志`,icon:Qr,run:()=>m(e=>!e)},...[{value:`all`,label:`全部资源`},{value:`fetch`,label:`Fetch/XHR`},{value:`doc`,label:`Doc`},{value:`css`,label:`CSS`},{value:`js`,label:`JS`},{value:`font`,label:`Font`},{value:`img`,label:`图片`},{value:`media`,label:`媒体`},{value:`manifest`,label:`Manifest`},{value:`websocket`,label:`WebSocket`},{value:`wasm`,label:`Wasm`},{value:`other`,label:`其他资源`}].map(e=>({id:`logs.resource.${e.value}`,title:`日志只看:${e.label}`,section:`日志`,icon:Kr,keywords:[`资源类型`,e.value],run:()=>{n(`/logs`),s(e.value)}})),{id:`request.detail`,title:`打开当前请求详情`,section:`日志`,icon:Wr,disabled:e.selectedRecordId==null,disabledReason:`请先在日志表里选择一条请求`,closeOnRun:!1,run:()=>t.openPanel({id:`request.detail`,title:`请求详情`,size:`lg`})},{id:`request.replay`,title:`重放当前请求`,section:`日志`,icon:pi,disabled:e.selectedRecordId==null,disabledReason:`请先在日志表里选择一条请求`,run:async()=>{e.selectedRecordId!=null&&await x(e.selectedRecordId)}},{id:`rules.ai`,title:`打开 AI 规则助手`,section:`路由规则`,icon:_i,keywords:[`AI`,`生成规则`,`合并规则`],closeOnRun:!1,run:()=>t.openPanel({id:`rules.ai`,title:`AI 规则助手`,description:`用自然语言生成规则,或安全合并当前配置`,size:`md`})},{id:`rules.preview`,title:`预览 URL 转发结果`,description:`输入 URL,使用当前规则计算真实转发地址`,section:`路由规则`,icon:hi,keywords:[`URL`,`preview`,`route`,`转发`,`预览`],closeOnRun:!1,run:()=>{t.openPanel({id:`rules.preview`,title:`URL 预览`,description:`使用当前编辑中的规则计算真实转发地址`,size:`md`})}},{id:`rules.overview`,title:`查看所有规则`,description:`总览全部规则文件与代理实际生效的路由规则`,section:`路由规则`,icon:Zr,keywords:[`全部`,`总览`,`overview`,`rules`,`生效`,`冲突`,`覆盖`],closeOnRun:!1,run:()=>{t.openPanel({id:`rules.overview`,title:`全局规则总览`,description:`总览全部规则文件与代理实际生效的路由规则`,size:`lg`})}},{id:`rules.add`,title:`添加路由规则`,section:`路由规则`,icon:Ur,disabled:!e.activeFileName,disabledReason:`请先选择或创建一个规则文件`,run:()=>{n(`/config`),e.setRules(e=>[{enabled:!0,rule:``,target:``,exclusions:[]},...e])}},{id:`rules.save`,title:`保存当前规则文件`,description:e.activeFileName?`保存 ${e.activeFileName}`:void 0,section:`路由规则`,icon:mi,disabled:!e.activeFileName,disabledReason:`请先选择一个规则文件`,run:async()=>{if(!e.activeFileName)return;let t=!1;try{t=await e.saveFileContent(e.activeFileName,e.rules)}catch(e){De.error(e instanceof Error?e.message:`规则保存失败`);return}t?(await e.fetchRuleFiles(),De.success(`规则保存成功`)):De.error(`规则保存失败`)}},{id:`rules.create-file`,title:`创建规则文件`,section:`路由规则`,icon:Ur,run:async()=>{let t=window.prompt(`请输入规则文件名称`);if(!t?.trim())return;let r=await e.createRuleFile(t.trim());r.success?(n(`/config`),await e.fetchFileContent(t.trim())):r.error&&window.alert(r.error)}},...e.ruleFiles.map(t=>({id:`rules.file.open.${t.name}`,title:`打开规则文件:${t.name}`,description:`${t.ruleCount} 条规则 · ${t.enabled?`已启用`:`未启用`}`,section:`规则文件`,icon:Wr,keywords:[`规则文件`,t.name],run:async()=>{n(`/config`),await e.fetchFileContent(t.name)}})),...e.ruleFiles.map(t=>({id:`rules.file.toggle.${t.name}`,title:`${t.enabled?`禁用`:`启用`}规则文件:${t.name}`,section:`规则文件`,icon:di,keywords:[`规则文件`,t.name,`启用`,`禁用`],run:async()=>{await e.toggleRuleFile(t.name,!t.enabled)}})),...e.ruleFiles.map(t=>({id:`rules.file.delete.${t.name}`,title:`删除规则文件:${t.name}`,section:`规则文件`,icon:S,danger:!0,confirm:`确定要删除规则文件「${t.name}」吗?`,keywords:[`规则文件`,t.name,`删除`],run:async()=>{await e.deleteRuleFile(t.name)}})),{id:`mock.create`,title:`新建 Mock 规则`,section:`Mock`,icon:Rr,keywords:[`mock`,`新增规则`],closeOnRun:!1,run:()=>t.openPanel({id:`mock.create`,title:`新建 Mock 规则`,size:`lg`})},...e.mockRules.map(e=>({id:`mock.edit.${e.id}`,title:`编辑 Mock:${e.name||e.urlPattern}`,description:`${e.method||`*`} ${e.urlPattern}`,section:`Mock`,icon:ci,keywords:[`mock`,e.name,e.urlPattern],closeOnRun:!1,run:()=>t.openPanel({id:`mock.edit`,title:`编辑 Mock:${e.name||e.urlPattern}`,size:`lg`,params:{id:e.id}})})),...e.mockRules.map(t=>({id:`mock.toggle.${t.id}`,title:`${t.enabled?`禁用`:`启用`} Mock:${t.name||t.urlPattern}`,description:`${t.method||`*`} ${t.urlPattern}`,section:`Mock`,icon:di,keywords:[`mock`,t.name,t.urlPattern,`启用`,`禁用`],run:async()=>{await e.updateMock(t.id,{enabled:!t.enabled}),await e.fetchMocks()}})),...e.mockRules.map(t=>({id:`mock.delete.${t.id}`,title:`删除 Mock:${t.name||t.urlPattern}`,description:`${t.method||`*`} ${t.urlPattern}`,section:`Mock`,icon:S,danger:!0,confirm:`确定要删除 Mock「${t.name||t.urlPattern}」吗?`,keywords:[`mock`,t.name,t.urlPattern,`删除`],run:async()=>{await e.deleteMock(t.id),await e.fetchMocks()}})),{id:`mock.refresh`,title:`刷新 Mock 列表`,section:`Mock`,icon:pi,run:e.fetchMocks},{id:`plugins.mode.off`,title:`关闭插件模式`,section:`插件`,icon:di,keywords:[`plugin`,`plugins`,`mode`,`off`,`插件模式`],run:()=>e.switchPluginMode(`off`)},{id:`plugins.mode.on`,title:`开启插件模式`,section:`插件`,icon:ui,keywords:[`plugin`,`plugins`,`mode`,`on`,`插件模式`],run:()=>e.switchPluginMode(`on`)},{id:`plugins.mode.shadow`,title:`切换到插件影子模式`,section:`插件`,icon:_i,keywords:[`plugin`,`plugins`,`mode`,`shadow`,`插件模式`,`影子模式`],run:()=>e.switchPluginMode(`shadow`)},{id:`plugins.generate`,title:`AI 生成插件`,section:`插件`,icon:Mr,keywords:[`plugin`,`plugins`,`generate`,`AI`,`插件生成`],closeOnRun:!1,run:()=>t.openPanel({id:`plugin.generate`,title:`AI 插件生成器`,size:`xl`})},{id:`plugins.reload`,title:`热加载插件`,section:`插件`,icon:pi,keywords:[`plugin`,`plugins`,`reload`,`hot reload`,`热加载`],run:async()=>{await fetch(`/api/plugins/reload`,{method:`POST`}),await e.fetchPlugins()}},...e.plugins.map(t=>({id:`plugins.runtime.${t.state===`running`?`stop`:`start`}.${t.id}`,title:`${t.state===`running`?`停止`:`启动`}插件:${t.name}`,description:`${t.version} · ${t.hooks.join(`, `)||`无 hooks`}`,section:`插件`,icon:t.state===`running`?vi:li,keywords:[`插件`,t.name,t.id,...t.hooks],run:async()=>{t.state===`running`?await e.stopPlugin(t.id):await e.startPlugin(t.id),await e.fetchPlugins()}})),...e.plugins.filter(e=>Ud(e)&&!!Wd(e)).map(e=>{let n=Wd(e);return{id:`plugins.edit.${e.id}`,title:`编辑插件代码:${e.name}`,description:n,section:`插件`,icon:zr,keywords:[`插件`,`代码`,e.name,e.id,n],closeOnRun:!1,run:()=>t.openPanel({id:`plugin.code`,title:`编辑插件代码:${n}`,size:`xl`,params:{filename:n}})}}),...e.plugins.filter(e=>Ud(e)&&!!Wd(e)).map(e=>({id:`plugins.test.${e.id}`,title:`测试插件:${e.name}`,description:e.hooks.join(`, `)||`无 hooks`,section:`插件`,icon:xi,keywords:[`插件`,`测试`,e.name,e.id,...e.hooks],closeOnRun:!1,run:()=>t.openPanel({id:`plugin.test`,title:`测试插件:${e.name}`,size:`xl`,params:{pluginId:e.id,pluginName:e.name,hooks:e.hooks,filename:Wd(e)}})})),...e.plugins.map(t=>({id:`plugins.toggle.${t.id}`,title:`${t.state===`disabled`?`启用`:`禁用`}插件:${t.name}`,description:t.id,section:`插件`,icon:di,keywords:[`插件`,t.name,t.id,`启用`,`禁用`],run:async()=>{await e.togglePlugin(t.id,t.state===`disabled`),await e.fetchPlugins()}})),...Cd()?[{id:`plugins.third-party.load`,title:`加载第三方插件`,section:`插件`,icon:Ci,keywords:[`plugin`,`plugins`,`third party`,`load`,`第三方插件`],run:async()=>{let t=window.prompt(`请输入第三方插件路径`);t?.trim()&&(await e.loadThirdPartyPlugin(t.trim()),await e.fetchThirdPartyPlugins())}},...e.thirdPartyPlugins.map(t=>({id:`plugins.third-party.unload.${t.id}`,title:`卸载第三方插件:${t.name}`,description:t.id,section:`插件`,icon:S,danger:!0,confirm:`确定要卸载第三方插件「${t.name}」吗?`,keywords:[`第三方插件`,t.name,t.id,`卸载`],run:async()=>{await e.unloadThirdPartyPlugin(t.id),await e.fetchThirdPartyPlugins()}}))]:[],{id:`settings.theme`,title:`主题与缩放设置`,section:`设置`,icon:Pr,keywords:[`settings`,`theme`,`zoom`,`主题`,`缩放`],closeOnRun:!1,run:()=>{n(`/settings`)}}],[p,x,n,d,s,e]),w=(0,k.useCallback)((t,r)=>{switch(t.id){case`settings`:return(0,N.jsx)(Yd,{embedded:!0});case`mobile-proxy`:return(0,N.jsx)(rf,{});case`request.detail`:return(0,N.jsx)(Jd,{embedded:!0,showTitle:!1,detail:e.recordDetail,loading:e.detailLoading,error:e.detailError,selectedRecord:e.records.find(t=>t.id===e.selectedRecordId),onCreateMock:b,onReplay:x,onJumpToRule:y});case`plugin.generate`:return(0,N.jsx)(Xd,{embedded:!0,onOpenChange:e=>{e||r.close()},onPluginSaved:async()=>{await e.fetchPlugins()}});case`mock.create`:return(0,N.jsx)(ef,{initialData:t.params?.initialData,createMock:e.createMock,updateMock:e.updateMock,onSaved:()=>{e.fetchMocks(),r.close()}});case`mock.edit`:{let n=Number(t.params?.id),i=e.mockRules.find(e=>e.id===n);return i?(0,N.jsx)(ef,{rule:i,createMock:e.createMock,updateMock:e.updateMock,onSaved:()=>{e.fetchMocks(),r.close()}}):(0,N.jsx)(`div`,{className:`flex h-full items-center justify-center p-6 text-sm text-muted-foreground`,children:`没有找到这条 Mock 规则`})}case`plugin.code`:return(0,N.jsx)(Zd,{embedded:!0,filename:String(t.params?.filename||``),onOpenChange:e=>{e||r.close()},onSaved:e.fetchPlugins});case`plugin.test`:return(0,N.jsx)(Qd,{embedded:!0,pluginId:String(t.params?.pluginId||``),pluginName:String(t.params?.pluginName||``),hooks:Array.isArray(t.params?.hooks)?t.params.hooks:[],filename:typeof t.params?.filename==`string`?t.params.filename:void 0,onOpenChange:e=>{e||r.close()},onPluginFixed:e.fetchPlugins});case`rules.ai`:return(0,N.jsx)($d,{rules:e.rules,setRules:e.setRules,ruleFiles:e.ruleFiles,activeFileName:e.activeFileName,fetchRuleFileRawContent:e.fetchRuleFileRawContent});case`rules.preview`:return(0,N.jsx)(tf,{embedded:!0,rules:e.rules,activeFileName:e.activeFileName,onRevealRule:e=>{r.close(),n(`/config`),window.setTimeout(()=>{window.dispatchEvent(new CustomEvent(`route-rule:highlight`,{detail:{pattern:e.pattern,target:e.target}}))},120)}});case`rules.overview`:return(0,N.jsx)(nf,{rules:e.rules,activeFileName:e.activeFileName,onLocateRule:(t,i,a)=>{r.close(),n(`/config`),e.fetchFileContent(t).then(()=>{window.setTimeout(()=>{window.dispatchEvent(new CustomEvent(`route-rule:highlight`,{detail:{pattern:i,target:a}}))},120)})},onSelectFile:t=>{r.close(),n(`/config`),e.fetchFileContent(t)}});default:return(0,N.jsx)(`div`,{className:`flex h-full items-center justify-center p-6 text-sm text-muted-foreground`,children:`未找到这个面板`})}},[b,y,x,n,e]),re=u;return(0,k.useEffect)(()=>{t()},[t]),(0,N.jsx)(Bd,{commands:ne,renderPanel:(e,t)=>(0,N.jsx)(k.Suspense,{fallback:(0,N.jsx)(of,{}),children:w(e,t)}),children:(0,N.jsxs)(`div`,{className:`flex h-dvh flex-col overflow-hidden bg-muted/20`,children:[(0,N.jsx)(Ou,{onCommandClick:C}),(0,N.jsx)(Lu,{}),(0,N.jsxs)(`main`,{className:`app-shell-main`,children:[(0,N.jsx)(Du,{activeTab:h,onTabChange:v,mockEnabledCount:e.mockRules.filter(e=>e.enabled).length}),g===`work`?(0,N.jsx)(`div`,{"data-testid":`shell-work`,"data-shell-mode":`work`,className:`mt-[var(--ui-section-gap)] flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:(0,N.jsx)(wi,{"data-testid":`log-panel-card`,className:`flex h-full min-h-0 flex-1 flex-col gap-0 overflow-hidden py-0 shadow-none`,children:(0,N.jsx)(xl,{detailOpen:e.selectedRecordId!=null,master:(0,N.jsxs)(`div`,{className:`app-page-pad flex min-h-0 flex-1 flex-col overflow-hidden`,children:[(0,N.jsxs)(`div`,{className:`shrink-0 border-b pb-[var(--ui-section-gap)]`,children:[(0,N.jsx)(`span`,{className:`sr-only`,children:`请求日志`}),(0,N.jsx)(Ec,{filterText:i,setFilterText:a,resourceTypeFilter:o,setResourceTypeFilter:s,clientSourceFilter:c,setClientSourceFilter:l,totalCount:e.records.length,filteredCount:u.length,onClear:e.clearRecords,recording:d,onToggleRecording:()=>f(e=>!e)})]}),(0,N.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,children:(0,N.jsx)(ml,{records:re,selectedRecordId:e.selectedRecordId,onSelect:te,autoScroll:p})})]}),detail:(0,N.jsx)(k.Suspense,{fallback:(0,N.jsx)(of,{}),children:(0,N.jsx)(Jd,{embedded:!0,onClose:e.closeDetail,detail:e.recordDetail,loading:e.detailLoading,error:e.detailError,selectedRecord:e.records.find(t=>t.id===e.selectedRecordId),onCreateMock:b,onReplay:x,onJumpToRule:y})})})})}):(0,N.jsx)(`div`,{"data-testid":`shell-config`,"data-shell-mode":`config`,className:`mt-[var(--ui-section-gap)] flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:(0,N.jsxs)(wi,{className:`h-full min-h-0 w-full flex-1 gap-0 overflow-hidden rounded-b-none py-0`,children:[h===`config`&&(0,N.jsx)(`div`,{"data-testid":`config-page-rules`,className:`mt-0 flex min-h-0 flex-1 flex-col overflow-hidden`,children:(0,N.jsx)(k.Suspense,{fallback:(0,N.jsx)(of,{}),children:(0,N.jsx)(Gd,{rules:e.rules,setRules:e.setRules,ruleFiles:e.ruleFiles,activeFileName:e.activeFileName,fetchRuleFiles:e.fetchRuleFiles,fetchFileContent:e.fetchFileContent,fetchRuleFileRawContent:e.fetchRuleFileRawContent,saveRuleFileRawContent:e.saveRuleFileRawContent,saveFileContent:e.saveFileContent,createRuleFile:e.createRuleFile,toggleRuleFile:e.toggleRuleFile,renameRuleFile:e.renameRuleFile,deleteRuleFile:e.deleteRuleFile,reorderRuleFiles:e.reorderRuleFiles,setRuleFileReadonly:e.setRuleFileReadonly})})}),h===`mock`&&(0,N.jsx)(`div`,{"data-testid":`config-page-mock`,className:`mt-0 flex min-h-0 flex-1 flex-col overflow-hidden`,children:(0,N.jsx)(k.Suspense,{fallback:(0,N.jsx)(of,{}),children:(0,N.jsx)(Kd,{mockRules:e.mockRules,fetchMocks:e.fetchMocks,createMock:e.createMock,updateMock:e.updateMock,deleteMock:e.deleteMock})})}),h===`plugins`&&(0,N.jsx)(`div`,{"data-testid":`config-page-plugins`,className:`mt-0 flex min-h-0 flex-1 flex-col overflow-hidden`,children:(0,N.jsx)(k.Suspense,{fallback:(0,N.jsx)(of,{}),children:(0,N.jsx)(qd,{plugins:e.plugins,pluginMode:e.pluginMode,switchPluginMode:e.switchPluginMode,fetchPlugins:e.fetchPlugins,startPlugin:e.startPlugin,stopPlugin:e.stopPlugin,togglePlugin:e.togglePlugin,thirdPartyPlugins:e.thirdPartyPlugins,thirdPartySecurity:e.thirdPartySecurity,fetchThirdPartyPlugins:e.fetchThirdPartyPlugins,loadThirdPartyPlugin:e.loadThirdPartyPlugin,unloadThirdPartyPlugin:e.unloadThirdPartyPlugin})})}),h===`health`&&(0,N.jsx)(`div`,{"data-testid":`config-page-health`,className:`meddle-thin-scroll mt-0 min-h-0 flex-1 overflow-y-auto`,children:(0,N.jsx)(k.Suspense,{fallback:(0,N.jsx)(of,{}),children:(0,N.jsx)(af,{})})}),h===`settings`&&(0,N.jsx)(`div`,{"data-testid":`config-page-settings`,className:`meddle-thin-scroll mt-0 flex min-h-0 flex-1 flex-col overflow-hidden`,children:(0,N.jsx)(k.Suspense,{fallback:(0,N.jsx)(of,{}),children:(0,N.jsx)(Yd,{embedded:!0})})}),h===`mobile`&&(0,N.jsx)(`div`,{"data-testid":`config-page-mobile`,className:`meddle-thin-scroll mt-0 min-h-0 flex-1 overflow-y-auto`,children:(0,N.jsx)(k.Suspense,{fallback:(0,N.jsx)(of,{}),children:(0,N.jsx)(rf,{})})})]})})]})]})})}function cf({position:e=`bottom-right`,duration:t=ke,...n}){let{resolvedTheme:r}=mu();return(0,N.jsx)(Oe,{theme:r,position:e,duration:t,expand:!0,closeButton:!0,gap:10,visibleToasts:4,offset:16,mobileOffset:12,swipeDirections:[`right`],className:`toaster group`,icons:{success:(0,N.jsx)(Ir,{className:`size-4`}),info:(0,N.jsx)(Xr,{className:`size-4`}),warning:(0,N.jsx)(Si,{className:`size-4`}),error:(0,N.jsx)(ni,{className:`size-4`}),loading:(0,N.jsx)($r,{className:`size-4 animate-spin`}),close:(0,N.jsx)(ae,{className:`size-3`})},toastOptions:{unstyled:!0,closeButtonAriaLabel:`关闭通知`,style:{"--system-toast-duration":`${ke}ms`},classNames:{toast:`system-toast`,content:`system-toast-content`,title:`system-toast-title`,description:`system-toast-description`,icon:`system-toast-icon`,closeButton:`system-toast-close`,actionButton:`system-toast-action`,cancelButton:`system-toast-cancel`,success:`system-toast-success`,info:`system-toast-info`,warning:`system-toast-warning`,error:`system-toast-error`,loading:`system-toast-loading`,default:`system-toast-default`}},...n})}function lf({children:e}){let t=(0,k.useRef)(new Map),n=(0,k.useRef)(0),r=(0,k.useCallback)(e=>{t.current.set(e,{order:n.current++})},[]),i=(0,k.useCallback)((e,i)=>{t.current.get(e)||r(e);let a=t.current.get(e);a&&(!a.registration?.active&&i.active&&(a.order=n.current++),a.registration=i)},[r]),a=(0,k.useCallback)(e=>{t.current.delete(e)},[]);(0,k.useEffect)(()=>{let e=e=>{if(e.isComposing||e.repeat||!(e.metaKey||e.ctrlKey)||e.key.toLowerCase()!==`s`)return;let n=[...t.current.values()].filter(e=>!!e.registration?.active).sort((e,t)=>t.registration.priority-e.registration.priority||t.order-e.order)[0];n&&(e.preventDefault(),e.stopPropagation(),n.registration.enabled&&n.registration.onSave())};return window.addEventListener(`keydown`,e,{capture:!0}),()=>window.removeEventListener(`keydown`,e,{capture:!0})},[]);let o=(0,k.useMemo)(()=>({register:r,update:i,unregister:a}),[r,a,i]);return(0,N.jsx)(eu.Provider,{value:o,children:e})}(0,Pe.createRoot)(document.getElementById(`root`)).render((0,N.jsx)(k.StrictMode,{children:(0,N.jsxs)(pu,{defaultTheme:`light`,storageKey:`theme`,children:[(0,N.jsx)(lf,{children:(0,N.jsx)(sr,{children:(0,N.jsx)(sf,{})})}),(0,N.jsx)(cf,{})]})}));export{ji as $,Sl as A,Ir as At,Xc as B,ql as C,Qr as Ct,Ol as D,Wr as Dt,J as E,Kr as Et,nl as F,xc as G,Jc as H,tl as I,bc as J,vc as K,Qc as L,wl as M,Ar as Mt,Tl as N,Or as Nt,Al as O,Hr as Ot,bl as P,ze as Pt,fc as Q,Gc as R,Gl as S,$r as St,Kl as T,qr as Tt,Yc as U,Kc as V,_c as W,hc as X,yc as Y,gc as Z,tu as _,fi as _t,Cd as a,Ti as at,Jl as b,ti as bt,Yu as c,xi as ct,sd as d,vi as dt,Ai as et,mu as f,_i as ft,nu as g,pi as gt,cu as h,mi as ht,Fd as i,Di as it,El as j,Mr as jt,kl as k,zr as kt,Zu as l,bi as lt,au as m,hi as mt,Hd as n,Oi as nt,vd as o,Ei as ot,su as p,gi as pt,Sc as q,Id as r,ki as rt,Xu as s,Si as st,Wd as t,wi as tt,Qu as u,yi as ut,$l as v,di as vt,Y as w,Zr as wt,Hl as x,ei as xt,Xl as y,li as yt,Zc as z};
|
|
21
|
+
`,r=t.split(/\r?\n/).map(e=>{let t=Qu(e);return{raw:e,items:t.length>0?t:null}}),i=[],a=[];r.forEach((e,t)=>{e.items?.forEach((e,n)=>{i.push({entry:t,k:n}),a.push(e)})});let{matchA:o,matchB:s}=sd(a,e),c=new Set(a.map(e=>e.rule)),l=Array(r.length).fill(-1);i.forEach((e,t)=>{l[e.entry]<0&&(l[e.entry]=t)});let u=r.map((e,t)=>{if(!e.items)return!1;let n=l[t],r=o[n];return r<0?!1:e.items.every((e,t)=>o[n+t]===r+t)}),d=r.map((e,t)=>e.items?e.items.filter((e,n)=>o[l[t]+n]<0).length:0),f=Array(e.length+1).fill(r.length);for(let t=e.length-1;t>=0;t--)f[t]=s[t]>=0?i[s[t]].entry:f[t+1];let p=r.length;for(;p>0&&!r[p-1].raw.trim();)p--;let m=[],h=0,g=e=>{for(;h<e;h++)r[h].items||m.push(r[h].raw)},_=0;for(;_<e.length;){let t=s[_];if(t>=0){let{entry:n,k:a}=i[t];g(n);let o=r[n].items;if(u[n]&&a===0){m.push(r[n].raw),_+=o.length,h=n+1;continue}m.push(ad(e[_],c)),_++;continue}let n=f[_+1],a=!1;for(let e=h;e<n;e++)if(r[e].items&&d[e]>0){g(e),d[e]--,a=!0;break}!a&&n===r.length&&g(p),m.push(ad(e[_],c)),_++}return g(r.length),m.join(n)}var ld=`X-Meddle-UI-Token`,ud=`meddle-ui-token`,dd=null;function fd(){if(typeof document>`u`)return null;let e=document.querySelector(`meta[name="${ud}"]`)?.getAttribute(`content`);return e&&e.trim()?e.trim():null}async function pd(){try{let e=await fetch(`/api/ui-token`,{cache:`no-store`,credentials:`same-origin`});if(!e.ok)return null;let t=await e.json();return typeof t.token==`string`&&t.token?t.token:null}catch{return null}}async function md(e=!1){return!e&&(dd||=fd(),dd)||(dd=await pd()),dd}async function hd(e,t){for(let n=0;n<2;n+=1){let r=await md(n>0);try{let i=await fetch(`/api/rule-files/${encodeURIComponent(e)}/readonly`,{method:`PUT`,credentials:`same-origin`,headers:{"Content-Type":`application/json`,...r?{[ld]:r}:{}},body:JSON.stringify({readonly:t})}),a=await i.json().catch(()=>null);if(i.ok&&a?.status===`success`)return{success:!0};if(i.status===403&&a?.code===`UI_TOKEN_INVALID`&&n===0)continue;return{success:!1,error:a?.error||`保存失败(${i.status})`}}catch(e){return{success:!1,error:e instanceof Error?e.message:`保存失败`}}}return{success:!1,error:`保存失败`}}function gd(){let[e,t]=(0,k.useState)([]),[n,r]=(0,k.useState)([]),[i,a]=(0,k.useState)(null),o=(0,k.useRef)(new Map),s=(0,k.useCallback)(async()=>{try{let e=await(await fetch(`/api/rule-files`)).json(),t=Array.isArray(e)?e:[];return r(t),t}catch(e){return console.error(`Failed to fetch rule files:`,e),[]}},[]),c=(0,k.useCallback)(async e=>{let t=await fetch(`/api/rule-files/${encodeURIComponent(e)}/content`);return new TextDecoder(`utf-8`,{ignoreBOM:!0}).decode(await t.arrayBuffer())},[]),l=(0,k.useCallback)(async e=>{try{let n=await c(e);o.current.set(e,n),t(Qu(n)),a(e)}catch(e){console.error(`Failed to fetch file content:`,e)}},[c]),u=(0,k.useCallback)(async(e,t)=>{try{let n=await(await fetch(`/api/rule-files/${encodeURIComponent(e)}/content`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({content:t})})).json();return n.status===`success`&&o.current.set(e,t),n.status===`success`}catch(e){return console.error(`Failed to save file content:`,e),!1}},[]);return{rules:e,setRules:t,ruleFiles:n,activeFileName:i,fetchRuleFiles:s,fetchFileContent:l,fetchRuleFileRawContent:c,saveRuleFileRawContent:u,saveFileContent:(0,k.useCallback)(async(e,t)=>u(e,cd(t,o.current.get(e)??``)),[u]),createRuleFile:(0,k.useCallback)(async(e,t=``)=>{let n=e.trim();try{let e=await(await fetch(`/api/rule-files`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:n,content:t,enabled:!0})})).json();return e.status===`success`?(await s(),{success:!0}):{success:!1,error:e.error}}catch(e){return(await s()).some(e=>e.name===n)?{success:!0}:{success:!1,error:e instanceof Error?e.message:`创建规则文件失败`}}},[s]),toggleRuleFile:(0,k.useCallback)(async(e,t)=>{try{return(await(await fetch(`/api/rule-files/${encodeURIComponent(e)}`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({enabled:t})})).json()).status===`success`?(await s(),!0):!1}catch(e){return console.error(`Failed to toggle rule file:`,e),!1}},[s]),renameRuleFile:(0,k.useCallback)(async(e,t)=>{let n=t.trim();if(!n)return{success:!1,error:`规则文件名称不能为空`};try{let t=await(await fetch(`/api/rule-files/${encodeURIComponent(e)}`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({newName:n})})).json();if(t.status!==`success`)return{success:!1,error:t.error||`重命名失败`};let r=typeof t.name==`string`?t.name:n;if(r!==e){let t=o.current.get(e);t!==void 0&&o.current.set(r,t),o.current.delete(e)}return i===e&&a(r),await s(),{success:!0,name:r}}catch(e){return{success:!1,error:e instanceof Error?e.message:`重命名失败`}}},[i,s]),deleteRuleFile:(0,k.useCallback)(async e=>{try{return(await(await fetch(`/api/rule-files/${encodeURIComponent(e)}`,{method:`DELETE`})).json()).status===`success`?(i===e&&(a(null),t([])),await s(),!0):!1}catch(e){return console.error(`Failed to delete rule file:`,e),!1}},[s,i]),reorderRuleFiles:(0,k.useCallback)(async e=>{let t=n,i=new Map(t.map(e=>[e.name,e])),a=e.map(e=>i.get(e)).filter(e=>!!e);a.length===e.length&&r(a);try{return(await(await fetch(`/api/rule-files/order`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({order:e})})).json()).status===`success`?(await s(),!0):(r(t),await s(),!1)}catch(e){return console.error(`Failed to reorder rule files:`,e),r(t),await s(),!1}},[s,n]),setRuleFileReadonly:(0,k.useCallback)(async(e,t)=>{let n=await hd(e,t);return n.success&&(r(n=>n.map(n=>n.name===e?{...n,readonly:t}:n)),s()),n},[s])}}var _d=`mocksUpdated`,vd=!1;function yd(){let e=vd;return vd=!1,e}function Q(e,t={}){let n=e;n?.code===`MOCKS_FILE_INVALID`&&(vd=!0,t.silent||De.error(n.error||`Mock 文件格式错误`),window.dispatchEvent(new CustomEvent(Ae)))}function bd(e,t){return e.some(e=>e.id===t.id)?Sd(e,t):e}function xd(e){let t=new Map;for(let n of e)t.set(n.id,n);return Array.from(t.values()).sort((e,t)=>e.id-t.id)}function Sd(e,t){return xd([...e.filter(e=>e.id!==t.id),t])}function Cd(){let[e,t]=(0,k.useState)([]),n=(0,k.useCallback)(async()=>{try{let e=await(await fetch(`/api/mocks`,{cache:`no-store`})).json();t(xd(Array.isArray(e)?e:[]))}catch(e){console.error(`Failed to fetch mocks:`,e)}},[]);return(0,k.useEffect)(()=>{n()},[n]),(0,k.useEffect)(()=>{let e=e=>{let n=e;t(xd(Array.isArray(n.detail)?n.detail:[]))};return window.addEventListener(_d,e),()=>window.removeEventListener(_d,e)},[]),{mockRules:e,fetchMocks:n,createMock:(0,k.useCallback)(async(e,n)=>{try{let r=await(await fetch(`/api/mocks`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)})).json();return r.status===`success`?(t(e=>Sd(e,r.rule)),r.rule):(Q(r,{silent:n?.silentInvalid}),null)}catch(e){return console.error(`Failed to create mock:`,e),null}},[]),updateMock:(0,k.useCallback)(async(e,n,r)=>{let i;t(t=>(i=t.find(t=>t.id===e),i?Sd(t,{...i,...n}):t));try{let a=await(await fetch(`/api/mocks/${e}`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)})).json();if(a.status===`success`)return t(e=>Sd(e,a.rule)),!0;if(Q(a,{silent:r?.silentInvalid}),i){let e=i;t(t=>bd(t,e))}return!1}catch(e){if(console.error(`Failed to update mock:`,e),i){let e=i;t(t=>bd(t,e))}return!1}},[]),deleteMock:(0,k.useCallback)(async e=>{try{let n=await(await fetch(`/api/mocks/${e}`,{method:`DELETE`})).json();return n.status===`success`?(t(t=>t.filter(t=>t.id!==e)),!0):(Q(n),!1)}catch(e){return console.error(`Failed to delete mock:`,e),!1}},[])}}function wd(){return!1}function Td(){let[e,t]=(0,k.useState)([]),[n,r]=(0,k.useState)(`off`),[i,a]=(0,k.useState)([]),[o,s]=(0,k.useState)({allowAll:!1,trusted:[]}),c=(0,k.useCallback)(async()=>{try{let e=await(await fetch(`/api/plugins`)).json();r(e.mode||`off`),t(e.plugins||[])}catch(e){console.error(`Failed to fetch plugins:`,e)}},[]);return{plugins:e,pluginMode:n,switchPluginMode:(0,k.useCallback)(async e=>{try{(await fetch(`/api/pipeline/mode`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({mode:e})})).ok&&r(e)}catch(e){console.error(`Failed to switch plugin mode:`,e)}},[]),thirdPartyPlugins:i,thirdPartySecurity:o,fetchPlugins:c,startPlugin:(0,k.useCallback)(async e=>{try{await fetch(`/api/plugins/${e}/start`,{method:`POST`})}catch(e){console.error(`Failed to start plugin:`,e)}},[]),stopPlugin:(0,k.useCallback)(async e=>{try{await fetch(`/api/plugins/${e}/stop`,{method:`POST`})}catch(e){console.error(`Failed to stop plugin:`,e)}},[]),togglePlugin:(0,k.useCallback)(async(e,n)=>{try{(await fetch(`/api/plugins/${encodeURIComponent(e)}/toggle`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({enabled:n})})).ok&&t(t=>t.map(t=>t.id===e?{...t,state:n?`running`:`disabled`}:t))}catch(e){console.error(`Failed to toggle plugin:`,e)}},[]),fetchThirdPartyPlugins:(0,k.useCallback)(async()=>{if(wd())try{let e=await fetch(`/api/plugins/third-party`),t=e.headers.get(`content-type`)||``;if(!e.ok||!t.includes(`application/json`)){a([]),s({allowAll:!1,trusted:[]});return}let n=await e.json();a(n.plugins||[]),s(n.security||{allowAll:!1,trusted:[]})}catch(e){console.error(`Failed to fetch third-party plugins:`,e)}},[]),loadThirdPartyPlugin:(0,k.useCallback)(async e=>{if(wd())try{await fetch(`/api/plugins/third-party/load`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({path:e})})}catch(e){console.error(`Failed to load third-party plugin:`,e)}},[]),unloadThirdPartyPlugin:(0,k.useCallback)(async e=>{if(wd())try{await fetch(`/api/plugins/third-party/${e}/unload`,{method:`POST`})}catch(e){console.error(`Failed to unload third-party plugin:`,e)}},[])}}function Ed(){let[e,t]=(0,k.useState)(zu),n=Uu(e),r=gd(),i=Cd(),a=Td();return{records:n.records,selectedRecordId:n.selectedRecordId,recordDetail:n.recordDetail,detailLoading:n.detailLoading,detailError:n.detailError,fetchDetail:n.fetchDetail,closeDetail:n.closeDetail,clearRecords:n.clearRecords,replayRequest:n.replayRequest,maxRecords:e,setMaxRecords:t,rules:r.rules,setRules:r.setRules,ruleFiles:r.ruleFiles,activeFileName:r.activeFileName,fetchRuleFiles:r.fetchRuleFiles,fetchFileContent:r.fetchFileContent,fetchRuleFileRawContent:r.fetchRuleFileRawContent,saveRuleFileRawContent:r.saveRuleFileRawContent,saveFileContent:r.saveFileContent,createRuleFile:r.createRuleFile,toggleRuleFile:r.toggleRuleFile,renameRuleFile:r.renameRuleFile,deleteRuleFile:r.deleteRuleFile,reorderRuleFiles:r.reorderRuleFiles,setRuleFileReadonly:r.setRuleFileReadonly,mockRules:i.mockRules,fetchMocks:i.fetchMocks,createMock:i.createMock,updateMock:i.updateMock,deleteMock:i.deleteMock,plugins:a.plugins,pluginMode:a.pluginMode,switchPluginMode:a.switchPluginMode,thirdPartyPlugins:a.thirdPartyPlugins,thirdPartySecurity:a.thirdPartySecurity,fetchPlugins:a.fetchPlugins,startPlugin:a.startPlugin,stopPlugin:a.stopPlugin,togglePlugin:a.togglePlugin,fetchThirdPartyPlugins:a.fetchThirdPartyPlugins,loadThirdPartyPlugin:a.loadThirdPartyPlugin,unloadThirdPartyPlugin:a.unloadThirdPartyPlugin}}function Dd(e){let t=typeof e.source==`string`?e.source:``,n=typeof e.method==`string`?e.method:``,r=t.toLowerCase(),i=n.toUpperCase();if(!r)return`other`;if(r.startsWith(`ws://`)||r.startsWith(`wss://`))return`websocket`;if(i!==`GET`||r.includes(`/api/`)||r.includes(`.json`))return`fetch`;let a=r.split(`?`)[0].split(`#`)[0].split(`/`),o=a[a.length-1]||``,s=o.includes(`.`)&&o.split(`.`).pop()||``;return[`html`,`htm`,`php`,`asp`,`aspx`,`jsp`].includes(s)||!s&&i===`GET`?`doc`:s===`css`?`css`:[`js`,`mjs`,`jsx`,`ts`,`tsx`].includes(s)?`js`:[`woff`,`woff2`,`ttf`,`otf`,`eot`].includes(s)?`font`:[`png`,`jpg`,`jpeg`,`gif`,`svg`,`webp`,`ico`,`bmp`].includes(s)?`img`:[`mp4`,`webm`,`ogg`,`mp3`,`wav`,`flac`,`aac`,`m4a`].includes(s)?`media`:[`manifest`,`webmanifest`].includes(s)?`manifest`:s===`wasm`?`wasm`:`other`}var Od=new WeakMap;function kd(e){let t=Od.get(e);if(t)return t;let n=typeof e.method==`string`?e.method:``,r=typeof e.source==`string`?e.source:``,i=typeof e.target==`string`?e.target:``,a=typeof e.time==`string`?e.time:``,o=e.clientType||``,s=e.clientIp||``,c=e.clientName||``,l=e.applicationName||``,u=e.applicationProcess||``,d=e.applicationBundleId||``,f=e.applicationPid?.toString()||``,p=e.applicationIdentitySource||``,m=e.applicationIdentityConfidence||``,h=r;try{h=new URL(r).hostname}catch{}let g={methodUpper:n.toUpperCase(),statusCode:e.statusCode,statusText:e.statusCode?.toString()||``,sourceLower:r.toLowerCase(),domainLower:h.toLowerCase(),clientLower:`${o} ${c} ${s}`.toLowerCase(),clientIpLower:s.toLowerCase(),applicationLower:`${l} ${u} ${d} ${f} ${p} ${m}`.toLowerCase(),haystack:`${n} ${r} ${i} ${a} ${o} ${s} ${c} ${l} ${u} ${d} ${f} ${p} ${m}`.toLowerCase(),resourceType:Dd(e)};return Od.set(e,g),g}function Ad(e){let[t,n]=(0,k.useState)(``),[r,i]=(0,k.useState)(`all`),[a,o]=(0,k.useState)(`all`),s=(0,k.useDeferredValue)(t);return{filterText:t,setFilterText:n,resourceTypeFilter:r,setResourceTypeFilter:i,clientSourceFilter:a,setClientSourceFilter:o,filteredRecords:(0,k.useMemo)(()=>{let t=s.trim();if(!t&&r===`all`&&a===`all`)return e;let n=t.split(/\s+/).filter(Boolean),i=[];for(let t of e){if(a!==`all`&&t.clientType!==a)continue;let e=kd(t);r!==`all`&&e.resourceType!==r||n.every(t=>{let n=t.startsWith(`-`)&&t.length>1,r=n?t.slice(1):t,i=r.toLowerCase(),a=!1;if(i.startsWith(`method:`))a=e.methodUpper===r.slice(7).toUpperCase();else if(i.startsWith(`status:`)){let t=i.slice(7);if(!e.statusCode)a=!1;else if(t.includes(`x`)){let n=t.replace(/x/gi,``);a=e.statusText.startsWith(n)}else a=e.statusText===t}else a=i.startsWith(`domain:`)?e.domainLower.includes(i.slice(7))||e.sourceLower.includes(i.slice(7)):i.startsWith(`client:`)?e.clientLower.includes(i.slice(7)):i.startsWith(`ip:`)?e.clientIpLower.includes(i.slice(3)):i.startsWith(`app:`)?e.applicationLower.includes(i.slice(4)):jd(i,e.haystack);return n?!a:a})&&i.push(t)}return i},[e,s,r,a])}}function jd(e,t){if(t.includes(e))return!0;let n=0;for(let r=0;r<t.length&&n<e.length;r++)e[n]===t[r]&&n++;return n===e.length}var Md=[`content-length`,`content-encoding`,`connection`,`date`,`etag`,`last-modified`,`server`];function $(e){if(!e)return{};let t={};return Object.entries(e).forEach(([e,n])=>{Md.includes(e.toLowerCase())||(t[e]=n)}),t}function Nd(e){let t=e.match(/^\(truncated, \d+ bytes\)\n/);return t?e.substring(t[0].length):e}function Pd(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Fd(e){let t=$(e.responseHeaders),n=Nd(e.responseBody);return{urlPattern:Pd(e.source),body:n,statusCode:e.statusCode,headers:t,name:`从日志创建`,method:`*`,enabled:!0}}var Id=`mock-config:open-create`,Ld=(0,k.createContext)(null);function Rd(e){(0,k.useEffect)(()=>{let t=t=>{t.isComposing||t.key.toLowerCase()===`k`&&(t.metaKey||t.ctrlKey)&&(t.preventDefault(),e())};return window.addEventListener(`keydown`,t,{capture:!0}),()=>window.removeEventListener(`keydown`,t,{capture:!0})},[e])}var zd=(0,k.lazy)(()=>ze(()=>import(`./global-panel-shell-Iir-c_pQ.js`).then(e=>({default:e.GlobalPanelShell})),__vite__mapDeps([0,1,2,3,4,5,6,7,8]))),Bd=class extends k.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error(`Global panel failed to render`,e,t)}render(){return this.state.error?(0,N.jsx)(`div`,{className:`fixed inset-0 z-[82] flex items-center justify-center bg-background/80 p-6 backdrop-blur-sm`,children:(0,N.jsxs)(`div`,{className:`w-full max-w-lg rounded-lg border bg-card p-5 shadow-xl`,children:[(0,N.jsx)(`h2`,{className:`font-semibold`,children:`面板加载失败`}),(0,N.jsx)(`p`,{className:`mt-2 break-words text-sm text-destructive`,children:this.state.error.message}),(0,N.jsx)(`button`,{type:`button`,className:`mt-4 rounded-md border px-3 py-1.5 text-sm`,onClick:this.props.onClose,children:`关闭面板`})]})}):this.props.children}};function Vd({children:e,commands:t,renderPanel:n}){let[r,i]=(0,k.useState)(!1),[a,o]=(0,k.useState)([]),s=(0,k.useCallback)(()=>{o([]),i(!0)},[]),c=(0,k.useCallback)(e=>{o([e]),i(!0)},[]),l=(0,k.useCallback)(e=>{o(t=>[...t,e]),i(!0)},[]),u=(0,k.useCallback)(()=>{o(e=>e.slice(0,-1))},[]),d=(0,k.useCallback)(()=>{i(!1),o([])},[]);Rd(s),(0,k.useEffect)(()=>{let e=()=>s(),t=e=>{let t=e.detail;t?.id&&c(t)};return window.addEventListener(`global-panel:open-command`,e),window.addEventListener(`global-panel:open-panel`,t),()=>{window.removeEventListener(`global-panel:open-command`,e),window.removeEventListener(`global-panel:open-panel`,t)}},[s,c]);let f=a.length>0?a[a.length-1]:null,p=(0,k.useMemo)(()=>({open:r,stack:a,currentRoute:f,openCommand:s,openPanel:c,pushPanel:l,back:u,close:d}),[u,d,f,r,s,c,l,a]),m=typeof t==`function`?t(p):t;return(0,N.jsxs)(Ld.Provider,{value:p,children:[e,r&&(0,N.jsx)(Bd,{onClose:d,children:(0,N.jsx)(k.Suspense,{fallback:null,children:(0,N.jsx)(zd,{commands:m,renderPanel:e=>n(e,p)})})},f?.id||`command`)]})}function Hd(e){return`local.${e.replace(/\.js$/,``)}`}function Ud(e,t,n=new Set){let r=new Set,i=t.map(t=>{let n=e.find(e=>e.filename===t.filename)??(t.pluginId?e.find(e=>e.id===t.pluginId):void 0)??e.find(e=>e.id===Hd(t.filename)&&e.source!==`builtin`&&(!e.filename||e.filename===t.filename));return n&&r.add(n.id),{filename:t.filename,file:t,pluginId:n?.id??t.pluginId??Hd(t.filename),loadedPlugin:n,fileDeleted:!1}});for(let t of e)r.has(t.id)||n.has(t.id)||!Wd(t)||(r.add(t.id),i.push({filename:Gd(t)||t.id,pluginId:t.id,loadedPlugin:t,fileDeleted:!0}));return{builtinPlugins:e.filter(e=>r.has(e.id)||n.has(e.id)?!1:e.source?e.source===`builtin`:!e.id.startsWith(`local.`)),customRows:i}}function Wd(e){return e.source?e.source===`custom`:e.id.startsWith(`local.`)}function Gd(e){return e.filename?e.filename:e.id.startsWith(`local.`)?`${e.id.slice(6)}.js`:``}var Kd=(0,k.lazy)(()=>ze(()=>import(`./rule-config-Cb4ejIXI.js`).then(e=>({default:e.RuleConfig})),__vite__mapDeps([9,1,10,2,5,11,12,6,13,3,4,14,15,16,17,18,19,20,21]))),qd=(0,k.lazy)(()=>ze(()=>import(`./mock-config-CGl50MIr.js`).then(e=>({default:e.MockConfig})),__vite__mapDeps([22,1,10,2,5,11,23,12,6,13,4,24,14,16,25,26,27,17,28,8,20,29,18,19]))),Jd=(0,k.lazy)(()=>ze(()=>import(`./plugin-config-Cg09TsuV.js`).then(e=>({default:e.PluginConfig})),__vite__mapDeps([30,1,10,2,5,11,4,31,32,33,25,17,18]))),Yd=(0,k.lazy)(()=>ze(()=>import(`./detail-panel-DZRKJG2W.js`).then(e=>({default:e.DetailPanel})),__vite__mapDeps([34,1,2,4,5,35,36,13,37,38,39,40,41,27,16,20,42]))),Xd=(0,k.lazy)(()=>ze(()=>import(`./settings-panel-CpQuE6nr.js`).then(e=>({default:e.SettingsPanel})),__vite__mapDeps([43,1,10,2,5,11,4,31,13,7,38,14,32,44,45,16,29,17,46,28,8]))),Zd=(0,k.lazy)(()=>ze(()=>import(`./plugin-generator-CT1f1tu0.js`).then(e=>({default:e.PluginGenerator})),__vite__mapDeps([47,1,2,4,5,13,38,24,40,27,16,25,17,48,49,8]))),Qd=(0,k.lazy)(()=>ze(()=>import(`./plugin-code-editor-DKE9dFEE.js`).then(e=>({default:e.PluginCodeEditor})),__vite__mapDeps([50,1,23,2,4,5,51,44,33,16,25,17,48,49,8]))),$d=(0,k.lazy)(()=>ze(()=>import(`./plugin-test-dialog-BbLIMnkJ.js`).then(e=>({default:e.PluginTestDialog})),__vite__mapDeps([52,1,23,2,4,5,35,36,7,38,51,32,27,25,48,49,8]))),ef=(0,k.lazy)(()=>ze(()=>import(`./rule-ai-assistant-panel-CtfUqdYG.js`).then(e=>({default:e.RuleAiAssistantPanel})),__vite__mapDeps([53,1,27,46,49,8]))),tf=(0,k.lazy)(()=>ze(()=>import(`./mock-editor-panel-xcCk23oH.js`).then(e=>({default:e.MockEditorPanel})),__vite__mapDeps([26,1,10,2,5,11,23,12,6,13,4,24,14,27,16,25,17,28,8,20]))),nf=(0,k.lazy)(()=>ze(()=>import(`./route-preview-CKO7nF4W.js`).then(e=>({default:e.RoutePreview})),__vite__mapDeps([54,1,36]))),rf=(0,k.lazy)(()=>ze(()=>import(`./rule-overview-panel-xtHTS27O.js`).then(e=>({default:e.RuleOverviewPanel})),__vite__mapDeps([55,1,2,32,15,19]))),af=(0,k.lazy)(()=>ze(()=>import(`./mobile-proxy-panel-CFcwa11A.js`).then(e=>({default:e.MobileProxyPanel})),__vite__mapDeps([56,1,2,13,40,32,41,45,57,16,46,42]))),of=(0,k.lazy)(()=>ze(()=>import(`./health-panel-Dmf-EhJz.js`).then(e=>({default:e.HealthPanel})),__vite__mapDeps([58,1,2,31,11,38,39,32,41,57,46,19])));function sf(){return(0,N.jsxs)(`div`,{className:`flex flex-col gap-3 p-6`,"aria-label":`加载中`,children:[(0,N.jsx)(Ai,{className:`h-5 w-32`}),(0,N.jsx)(Ai,{className:`h-9 w-full`}),(0,N.jsx)(Ai,{className:`h-64 w-full`})]})}function cf(){let e=Ed(),t=e.fetchPlugins,n=Zt(),r=Jt(),{filterText:i,setFilterText:a,resourceTypeFilter:o,setResourceTypeFilter:s,clientSourceFilter:c,setClientSourceFilter:l,filteredRecords:u}=Ad(e.records),[d,f]=(0,k.useState)(!0),[p,m]=(0,k.useState)(!0),h=bu(r.pathname),g=Su(h),_=bl(`(max-width: 900px)`),v=e=>{n(xu(e))},y=(0,k.useCallback)(t=>{e.closeDetail(),n(`/config`),window.setTimeout(()=>{window.dispatchEvent(new CustomEvent(`route-rule:highlight`,{detail:{pattern:t.source,target:t.target}}))},120)},[n,e]),b=(0,k.useCallback)(t=>{let r=Fd(t);e.closeDetail(),n(`/mock`),window.setTimeout(()=>{window.dispatchEvent(new CustomEvent(Id,{detail:{initialData:r}}))},120)},[n,e]),x=(0,k.useCallback)(async t=>{let n=await e.replayRequest(t);return e.fetchDetail(n.recordId),n},[e]),C=(0,k.useCallback)(()=>{window.dispatchEvent(new CustomEvent(`global-panel:open-command`))},[]),ee=(0,k.useCallback)(e=>{window.dispatchEvent(new CustomEvent(`global-panel:open-panel`,{detail:e}))},[]),te=(0,k.useCallback)(t=>{if(e.selectedRecordId===t){e.closeDetail();return}e.fetchDetail(t),_&&ee({id:`request.detail`,title:`请求详情`,size:`lg`})},[_,ee,e]),ne=(0,k.useCallback)(t=>[{id:`nav.logs`,title:`打开日志`,section:`导航`,icon:qr,keywords:[`logs`,`请求`],run:()=>n(`/logs`)},{id:`nav.rules`,title:`打开路由规则`,section:`导航`,icon:Wr,keywords:[`rules`,`config`],run:()=>n(`/config`)},{id:`nav.mock`,title:`打开 Mock`,section:`导航`,icon:Rr,keywords:[`mock`],run:()=>n(`/mock`)},{id:`nav.plugins`,title:`打开扩展插件`,section:`导航`,icon:ui,keywords:[`plugin`,`plugins`],run:()=>n(`/plugins`)},{id:`nav.health`,title:`打开运行健康`,section:`导航`,icon:Or,keywords:[`health`,`健康`,`watchdog`,`运行状态`],run:()=>n(`/health`)},{id:`panel.settings`,title:`打开系统设置`,description:`偏好、配置文件、AI 配置`,section:`全局`,icon:gi,keywords:[`settings`,`配置`,`AI`],closeOnRun:!1,run:()=>t.openPanel({id:`settings`,title:`系统设置`,description:`管理系统偏好、配置和 AI 功能`,size:`lg`})},{id:`panel.mobile-proxy`,title:`打开手机代理二维码`,description:`扫码配置手机代理并安装 HTTPS 根证书`,section:`全局`,icon:fi,keywords:[`手机`,`二维码`,`QR`,`remote`,`proxy`],closeOnRun:!1,run:()=>t.openPanel({id:`mobile-proxy`,title:`手机代理`,description:`扫描二维码,在手机上配置代理与 HTTPS 证书`,size:`md`})},{id:`logs.focus-filter`,title:`聚焦日志过滤器`,description:`输入 method:GET、domain:example.com 或关键词筛选请求`,section:`日志`,icon:hi,run:()=>{n(`/logs`),window.setTimeout(()=>document.getElementById(`proxy-log-filter`)?.focus(),50)}},{id:`logs.toggle-recording`,title:d?`暂停记录日志`:`恢复记录日志`,section:`日志`,icon:d?si:li,run:()=>f(e=>!e)},{id:`logs.clear`,title:`清空日志`,section:`日志`,icon:S,danger:!0,confirm:`确定要清空当前日志列表吗?`,run:e.clearRecords},{id:`logs.toggle-auto-scroll`,title:p?`关闭自动滚动`:`开启自动滚动`,section:`日志`,icon:Qr,run:()=>m(e=>!e)},...[{value:`all`,label:`全部资源`},{value:`fetch`,label:`Fetch/XHR`},{value:`doc`,label:`Doc`},{value:`css`,label:`CSS`},{value:`js`,label:`JS`},{value:`font`,label:`Font`},{value:`img`,label:`图片`},{value:`media`,label:`媒体`},{value:`manifest`,label:`Manifest`},{value:`websocket`,label:`WebSocket`},{value:`wasm`,label:`Wasm`},{value:`other`,label:`其他资源`}].map(e=>({id:`logs.resource.${e.value}`,title:`日志只看:${e.label}`,section:`日志`,icon:Kr,keywords:[`资源类型`,e.value],run:()=>{n(`/logs`),s(e.value)}})),{id:`request.detail`,title:`打开当前请求详情`,section:`日志`,icon:Wr,disabled:e.selectedRecordId==null,disabledReason:`请先在日志表里选择一条请求`,closeOnRun:!1,run:()=>t.openPanel({id:`request.detail`,title:`请求详情`,size:`lg`})},{id:`request.replay`,title:`重放当前请求`,section:`日志`,icon:pi,disabled:e.selectedRecordId==null,disabledReason:`请先在日志表里选择一条请求`,run:async()=>{e.selectedRecordId!=null&&await x(e.selectedRecordId)}},{id:`rules.ai`,title:`打开 AI 规则助手`,section:`路由规则`,icon:_i,keywords:[`AI`,`生成规则`,`合并规则`],closeOnRun:!1,run:()=>t.openPanel({id:`rules.ai`,title:`AI 规则助手`,description:`用自然语言生成规则,或安全合并当前配置`,size:`md`})},{id:`rules.preview`,title:`预览 URL 转发结果`,description:`输入 URL,使用当前规则计算真实转发地址`,section:`路由规则`,icon:hi,keywords:[`URL`,`preview`,`route`,`转发`,`预览`],closeOnRun:!1,run:()=>{t.openPanel({id:`rules.preview`,title:`URL 预览`,description:`使用当前编辑中的规则计算真实转发地址`,size:`md`})}},{id:`rules.overview`,title:`查看所有规则`,description:`总览全部规则文件与代理实际生效的路由规则`,section:`路由规则`,icon:Zr,keywords:[`全部`,`总览`,`overview`,`rules`,`生效`,`冲突`,`覆盖`],closeOnRun:!1,run:()=>{t.openPanel({id:`rules.overview`,title:`全局规则总览`,description:`总览全部规则文件与代理实际生效的路由规则`,size:`lg`})}},{id:`rules.add`,title:`添加路由规则`,section:`路由规则`,icon:Ur,disabled:!e.activeFileName,disabledReason:`请先选择或创建一个规则文件`,run:()=>{n(`/config`),e.setRules(e=>[{enabled:!0,rule:``,target:``,exclusions:[]},...e])}},{id:`rules.save`,title:`保存当前规则文件`,description:e.activeFileName?`保存 ${e.activeFileName}`:void 0,section:`路由规则`,icon:mi,disabled:!e.activeFileName,disabledReason:`请先选择一个规则文件`,run:async()=>{if(!e.activeFileName)return;let t=!1;try{t=await e.saveFileContent(e.activeFileName,e.rules)}catch(e){De.error(e instanceof Error?e.message:`规则保存失败`);return}t?(await e.fetchRuleFiles(),De.success(`规则保存成功`)):De.error(`规则保存失败`)}},{id:`rules.create-file`,title:`创建规则文件`,section:`路由规则`,icon:Ur,run:async()=>{let t=window.prompt(`请输入规则文件名称`);if(!t?.trim())return;let r=await e.createRuleFile(t.trim());r.success?(n(`/config`),await e.fetchFileContent(t.trim())):r.error&&window.alert(r.error)}},...e.ruleFiles.map(t=>({id:`rules.file.open.${t.name}`,title:`打开规则文件:${t.name}`,description:`${t.ruleCount} 条规则 · ${t.enabled?`已启用`:`未启用`}`,section:`规则文件`,icon:Wr,keywords:[`规则文件`,t.name],run:async()=>{n(`/config`),await e.fetchFileContent(t.name)}})),...e.ruleFiles.map(t=>({id:`rules.file.toggle.${t.name}`,title:`${t.enabled?`禁用`:`启用`}规则文件:${t.name}`,section:`规则文件`,icon:di,keywords:[`规则文件`,t.name,`启用`,`禁用`],run:async()=>{await e.toggleRuleFile(t.name,!t.enabled)}})),...e.ruleFiles.map(t=>({id:`rules.file.delete.${t.name}`,title:`删除规则文件:${t.name}`,section:`规则文件`,icon:S,danger:!0,confirm:`确定要删除规则文件「${t.name}」吗?`,keywords:[`规则文件`,t.name,`删除`],run:async()=>{await e.deleteRuleFile(t.name)}})),{id:`mock.create`,title:`新建 Mock 规则`,section:`Mock`,icon:Rr,keywords:[`mock`,`新增规则`],closeOnRun:!1,run:()=>t.openPanel({id:`mock.create`,title:`新建 Mock 规则`,size:`lg`})},...e.mockRules.map(e=>({id:`mock.edit.${e.id}`,title:`编辑 Mock:${e.name||e.urlPattern}`,description:`${e.method||`*`} ${e.urlPattern}`,section:`Mock`,icon:ci,keywords:[`mock`,e.name,e.urlPattern],closeOnRun:!1,run:()=>t.openPanel({id:`mock.edit`,title:`编辑 Mock:${e.name||e.urlPattern}`,size:`lg`,params:{id:e.id}})})),...e.mockRules.map(t=>({id:`mock.toggle.${t.id}`,title:`${t.enabled?`禁用`:`启用`} Mock:${t.name||t.urlPattern}`,description:`${t.method||`*`} ${t.urlPattern}`,section:`Mock`,icon:di,keywords:[`mock`,t.name,t.urlPattern,`启用`,`禁用`],run:async()=>{await e.updateMock(t.id,{enabled:!t.enabled}),await e.fetchMocks()}})),...e.mockRules.map(t=>({id:`mock.delete.${t.id}`,title:`删除 Mock:${t.name||t.urlPattern}`,description:`${t.method||`*`} ${t.urlPattern}`,section:`Mock`,icon:S,danger:!0,confirm:`确定要删除 Mock「${t.name||t.urlPattern}」吗?`,keywords:[`mock`,t.name,t.urlPattern,`删除`],run:async()=>{await e.deleteMock(t.id),await e.fetchMocks()}})),{id:`mock.refresh`,title:`刷新 Mock 列表`,section:`Mock`,icon:pi,run:e.fetchMocks},{id:`plugins.mode.off`,title:`关闭插件模式`,section:`插件`,icon:di,keywords:[`plugin`,`plugins`,`mode`,`off`,`插件模式`],run:()=>e.switchPluginMode(`off`)},{id:`plugins.mode.on`,title:`开启插件模式`,section:`插件`,icon:ui,keywords:[`plugin`,`plugins`,`mode`,`on`,`插件模式`],run:()=>e.switchPluginMode(`on`)},{id:`plugins.mode.shadow`,title:`切换到插件影子模式`,section:`插件`,icon:_i,keywords:[`plugin`,`plugins`,`mode`,`shadow`,`插件模式`,`影子模式`],run:()=>e.switchPluginMode(`shadow`)},{id:`plugins.generate`,title:`AI 生成插件`,section:`插件`,icon:Mr,keywords:[`plugin`,`plugins`,`generate`,`AI`,`插件生成`],closeOnRun:!1,run:()=>t.openPanel({id:`plugin.generate`,title:`AI 插件生成器`,size:`xl`})},{id:`plugins.reload`,title:`热加载插件`,section:`插件`,icon:pi,keywords:[`plugin`,`plugins`,`reload`,`hot reload`,`热加载`],run:async()=>{await fetch(`/api/plugins/reload`,{method:`POST`}),await e.fetchPlugins()}},...e.plugins.map(t=>({id:`plugins.runtime.${t.state===`running`?`stop`:`start`}.${t.id}`,title:`${t.state===`running`?`停止`:`启动`}插件:${t.name}`,description:`${t.version} · ${t.hooks.join(`, `)||`无 hooks`}`,section:`插件`,icon:t.state===`running`?vi:li,keywords:[`插件`,t.name,t.id,...t.hooks],run:async()=>{t.state===`running`?await e.stopPlugin(t.id):await e.startPlugin(t.id),await e.fetchPlugins()}})),...e.plugins.filter(e=>Wd(e)&&!!Gd(e)).map(e=>{let n=Gd(e);return{id:`plugins.edit.${e.id}`,title:`编辑插件代码:${e.name}`,description:n,section:`插件`,icon:zr,keywords:[`插件`,`代码`,e.name,e.id,n],closeOnRun:!1,run:()=>t.openPanel({id:`plugin.code`,title:`编辑插件代码:${n}`,size:`xl`,params:{filename:n}})}}),...e.plugins.filter(e=>Wd(e)&&!!Gd(e)).map(e=>({id:`plugins.test.${e.id}`,title:`测试插件:${e.name}`,description:e.hooks.join(`, `)||`无 hooks`,section:`插件`,icon:xi,keywords:[`插件`,`测试`,e.name,e.id,...e.hooks],closeOnRun:!1,run:()=>t.openPanel({id:`plugin.test`,title:`测试插件:${e.name}`,size:`xl`,params:{pluginId:e.id,pluginName:e.name,hooks:e.hooks,filename:Gd(e)}})})),...e.plugins.map(t=>({id:`plugins.toggle.${t.id}`,title:`${t.state===`disabled`?`启用`:`禁用`}插件:${t.name}`,description:t.id,section:`插件`,icon:di,keywords:[`插件`,t.name,t.id,`启用`,`禁用`],run:async()=>{await e.togglePlugin(t.id,t.state===`disabled`),await e.fetchPlugins()}})),...wd()?[{id:`plugins.third-party.load`,title:`加载第三方插件`,section:`插件`,icon:Ci,keywords:[`plugin`,`plugins`,`third party`,`load`,`第三方插件`],run:async()=>{let t=window.prompt(`请输入第三方插件路径`);t?.trim()&&(await e.loadThirdPartyPlugin(t.trim()),await e.fetchThirdPartyPlugins())}},...e.thirdPartyPlugins.map(t=>({id:`plugins.third-party.unload.${t.id}`,title:`卸载第三方插件:${t.name}`,description:t.id,section:`插件`,icon:S,danger:!0,confirm:`确定要卸载第三方插件「${t.name}」吗?`,keywords:[`第三方插件`,t.name,t.id,`卸载`],run:async()=>{await e.unloadThirdPartyPlugin(t.id),await e.fetchThirdPartyPlugins()}}))]:[],{id:`settings.theme`,title:`主题与缩放设置`,section:`设置`,icon:Pr,keywords:[`settings`,`theme`,`zoom`,`主题`,`缩放`],closeOnRun:!1,run:()=>{n(`/settings`)}}],[p,x,n,d,s,e]),w=(0,k.useCallback)((t,r)=>{switch(t.id){case`settings`:return(0,N.jsx)(Xd,{embedded:!0});case`mobile-proxy`:return(0,N.jsx)(af,{});case`request.detail`:return(0,N.jsx)(Yd,{embedded:!0,showTitle:!1,detail:e.recordDetail,loading:e.detailLoading,error:e.detailError,selectedRecord:e.records.find(t=>t.id===e.selectedRecordId),onCreateMock:b,onReplay:x,onJumpToRule:y});case`plugin.generate`:return(0,N.jsx)(Zd,{embedded:!0,onOpenChange:e=>{e||r.close()},onPluginSaved:async()=>{await e.fetchPlugins()}});case`mock.create`:return(0,N.jsx)(tf,{initialData:t.params?.initialData,createMock:e.createMock,updateMock:e.updateMock,onSaved:()=>{e.fetchMocks(),r.close()}});case`mock.edit`:{let n=Number(t.params?.id),i=e.mockRules.find(e=>e.id===n);return i?(0,N.jsx)(tf,{rule:i,createMock:e.createMock,updateMock:e.updateMock,onSaved:()=>{e.fetchMocks(),r.close()}}):(0,N.jsx)(`div`,{className:`flex h-full items-center justify-center p-6 text-sm text-muted-foreground`,children:`没有找到这条 Mock 规则`})}case`plugin.code`:return(0,N.jsx)(Qd,{embedded:!0,filename:String(t.params?.filename||``),onOpenChange:e=>{e||r.close()},onSaved:e.fetchPlugins});case`plugin.test`:return(0,N.jsx)($d,{embedded:!0,pluginId:String(t.params?.pluginId||``),pluginName:String(t.params?.pluginName||``),hooks:Array.isArray(t.params?.hooks)?t.params.hooks:[],filename:typeof t.params?.filename==`string`?t.params.filename:void 0,onOpenChange:e=>{e||r.close()},onPluginFixed:e.fetchPlugins});case`rules.ai`:return(0,N.jsx)(ef,{rules:e.rules,setRules:e.setRules,ruleFiles:e.ruleFiles,activeFileName:e.activeFileName,fetchRuleFileRawContent:e.fetchRuleFileRawContent});case`rules.preview`:return(0,N.jsx)(nf,{embedded:!0,rules:e.rules,activeFileName:e.activeFileName,onRevealRule:e=>{r.close(),n(`/config`),window.setTimeout(()=>{window.dispatchEvent(new CustomEvent(`route-rule:highlight`,{detail:{pattern:e.pattern,target:e.target}}))},120)}});case`rules.overview`:return(0,N.jsx)(rf,{rules:e.rules,activeFileName:e.activeFileName,onLocateRule:(t,i,a)=>{r.close(),n(`/config`),e.fetchFileContent(t).then(()=>{window.setTimeout(()=>{window.dispatchEvent(new CustomEvent(`route-rule:highlight`,{detail:{pattern:i,target:a}}))},120)})},onSelectFile:t=>{r.close(),n(`/config`),e.fetchFileContent(t)}});default:return(0,N.jsx)(`div`,{className:`flex h-full items-center justify-center p-6 text-sm text-muted-foreground`,children:`未找到这个面板`})}},[b,y,x,n,e]),re=u;return(0,k.useEffect)(()=>{t()},[t]),(0,N.jsx)(Vd,{commands:ne,renderPanel:(e,t)=>(0,N.jsx)(k.Suspense,{fallback:(0,N.jsx)(sf,{}),children:w(e,t)}),children:(0,N.jsxs)(`div`,{className:`flex h-dvh flex-col overflow-hidden bg-muted/20`,children:[(0,N.jsx)(ku,{onCommandClick:C}),(0,N.jsx)(Ru,{}),(0,N.jsxs)(`main`,{className:`app-shell-main`,children:[(0,N.jsx)(Ou,{activeTab:h,onTabChange:v,mockEnabledCount:e.mockRules.filter(e=>e.enabled).length}),g===`work`?(0,N.jsx)(`div`,{"data-testid":`shell-work`,"data-shell-mode":`work`,className:`mt-[var(--ui-section-gap)] flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:(0,N.jsx)(wi,{"data-testid":`log-panel-card`,className:`flex h-full min-h-0 flex-1 flex-col gap-0 overflow-hidden py-0 shadow-none`,children:(0,N.jsx)(xl,{detailOpen:e.selectedRecordId!=null,master:(0,N.jsxs)(`div`,{className:`app-page-pad flex min-h-0 flex-1 flex-col overflow-hidden`,children:[(0,N.jsxs)(`div`,{className:`shrink-0 border-b pb-[var(--ui-section-gap)]`,children:[(0,N.jsx)(`span`,{className:`sr-only`,children:`请求日志`}),(0,N.jsx)(Ec,{filterText:i,setFilterText:a,resourceTypeFilter:o,setResourceTypeFilter:s,clientSourceFilter:c,setClientSourceFilter:l,totalCount:e.records.length,filteredCount:u.length,onClear:e.clearRecords,recording:d,onToggleRecording:()=>f(e=>!e)})]}),(0,N.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,children:(0,N.jsx)(ml,{records:re,selectedRecordId:e.selectedRecordId,onSelect:te,autoScroll:p})})]}),detail:(0,N.jsx)(k.Suspense,{fallback:(0,N.jsx)(sf,{}),children:(0,N.jsx)(Yd,{embedded:!0,onClose:e.closeDetail,detail:e.recordDetail,loading:e.detailLoading,error:e.detailError,selectedRecord:e.records.find(t=>t.id===e.selectedRecordId),onCreateMock:b,onReplay:x,onJumpToRule:y})})})})}):(0,N.jsx)(`div`,{"data-testid":`shell-config`,"data-shell-mode":`config`,className:`mt-[var(--ui-section-gap)] flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:(0,N.jsxs)(wi,{className:`h-full min-h-0 w-full flex-1 gap-0 overflow-hidden rounded-b-none py-0`,children:[h===`config`&&(0,N.jsx)(`div`,{"data-testid":`config-page-rules`,className:`mt-0 flex min-h-0 flex-1 flex-col overflow-hidden`,children:(0,N.jsx)(k.Suspense,{fallback:(0,N.jsx)(sf,{}),children:(0,N.jsx)(Kd,{rules:e.rules,setRules:e.setRules,ruleFiles:e.ruleFiles,activeFileName:e.activeFileName,fetchRuleFiles:e.fetchRuleFiles,fetchFileContent:e.fetchFileContent,fetchRuleFileRawContent:e.fetchRuleFileRawContent,saveRuleFileRawContent:e.saveRuleFileRawContent,saveFileContent:e.saveFileContent,createRuleFile:e.createRuleFile,toggleRuleFile:e.toggleRuleFile,renameRuleFile:e.renameRuleFile,deleteRuleFile:e.deleteRuleFile,reorderRuleFiles:e.reorderRuleFiles,setRuleFileReadonly:e.setRuleFileReadonly})})}),h===`mock`&&(0,N.jsx)(`div`,{"data-testid":`config-page-mock`,className:`mt-0 flex min-h-0 flex-1 flex-col overflow-hidden`,children:(0,N.jsx)(k.Suspense,{fallback:(0,N.jsx)(sf,{}),children:(0,N.jsx)(qd,{mockRules:e.mockRules,fetchMocks:e.fetchMocks,createMock:e.createMock,updateMock:e.updateMock,deleteMock:e.deleteMock})})}),h===`plugins`&&(0,N.jsx)(`div`,{"data-testid":`config-page-plugins`,className:`mt-0 flex min-h-0 flex-1 flex-col overflow-hidden`,children:(0,N.jsx)(k.Suspense,{fallback:(0,N.jsx)(sf,{}),children:(0,N.jsx)(Jd,{plugins:e.plugins,pluginMode:e.pluginMode,switchPluginMode:e.switchPluginMode,fetchPlugins:e.fetchPlugins,startPlugin:e.startPlugin,stopPlugin:e.stopPlugin,togglePlugin:e.togglePlugin,thirdPartyPlugins:e.thirdPartyPlugins,thirdPartySecurity:e.thirdPartySecurity,fetchThirdPartyPlugins:e.fetchThirdPartyPlugins,loadThirdPartyPlugin:e.loadThirdPartyPlugin,unloadThirdPartyPlugin:e.unloadThirdPartyPlugin})})}),h===`health`&&(0,N.jsx)(`div`,{"data-testid":`config-page-health`,className:`meddle-thin-scroll mt-0 min-h-0 flex-1 overflow-y-auto`,children:(0,N.jsx)(k.Suspense,{fallback:(0,N.jsx)(sf,{}),children:(0,N.jsx)(of,{})})}),h===`settings`&&(0,N.jsx)(`div`,{"data-testid":`config-page-settings`,className:`meddle-thin-scroll mt-0 flex min-h-0 flex-1 flex-col overflow-hidden`,children:(0,N.jsx)(k.Suspense,{fallback:(0,N.jsx)(sf,{}),children:(0,N.jsx)(Xd,{embedded:!0})})}),h===`mobile`&&(0,N.jsx)(`div`,{"data-testid":`config-page-mobile`,className:`meddle-thin-scroll mt-0 min-h-0 flex-1 overflow-y-auto`,children:(0,N.jsx)(k.Suspense,{fallback:(0,N.jsx)(sf,{}),children:(0,N.jsx)(af,{})})})]})})]})]})})}function lf({position:e=`bottom-right`,duration:t=ke,...n}){let{resolvedTheme:r}=hu();return(0,N.jsx)(Oe,{theme:r,position:e,duration:t,expand:!0,closeButton:!0,gap:10,visibleToasts:4,offset:16,mobileOffset:12,swipeDirections:[`right`],className:`toaster group`,icons:{success:(0,N.jsx)(Ir,{className:`size-4`}),info:(0,N.jsx)(Xr,{className:`size-4`}),warning:(0,N.jsx)(Si,{className:`size-4`}),error:(0,N.jsx)(ni,{className:`size-4`}),loading:(0,N.jsx)($r,{className:`size-4 animate-spin`}),close:(0,N.jsx)(ae,{className:`size-3`})},toastOptions:{unstyled:!0,closeButtonAriaLabel:`关闭通知`,style:{"--system-toast-duration":`${ke}ms`},classNames:{toast:`system-toast`,content:`system-toast-content`,title:`system-toast-title`,description:`system-toast-description`,icon:`system-toast-icon`,closeButton:`system-toast-close`,actionButton:`system-toast-action`,cancelButton:`system-toast-cancel`,success:`system-toast-success`,info:`system-toast-info`,warning:`system-toast-warning`,error:`system-toast-error`,loading:`system-toast-loading`,default:`system-toast-default`}},...n})}function uf({children:e}){let t=(0,k.useRef)(new Map),n=(0,k.useRef)(0),r=(0,k.useCallback)(e=>{t.current.set(e,{order:n.current++})},[]),i=(0,k.useCallback)((e,i)=>{t.current.get(e)||r(e);let a=t.current.get(e);a&&(!a.registration?.active&&i.active&&(a.order=n.current++),a.registration=i)},[r]),a=(0,k.useCallback)(e=>{t.current.delete(e)},[]);(0,k.useEffect)(()=>{let e=e=>{if(e.isComposing||e.repeat||!(e.metaKey||e.ctrlKey)||e.key.toLowerCase()!==`s`)return;let n=[...t.current.values()].filter(e=>!!e.registration?.active).sort((e,t)=>t.registration.priority-e.registration.priority||t.order-e.order)[0];n&&(e.preventDefault(),e.stopPropagation(),n.registration.enabled&&n.registration.onSave())};return window.addEventListener(`keydown`,e,{capture:!0}),()=>window.removeEventListener(`keydown`,e,{capture:!0})},[]);let o=(0,k.useMemo)(()=>({register:r,update:i,unregister:a}),[r,a,i]);return(0,N.jsx)(tu.Provider,{value:o,children:e})}(0,Pe.createRoot)(document.getElementById(`root`)).render((0,N.jsx)(k.StrictMode,{children:(0,N.jsxs)(mu,{defaultTheme:`light`,storageKey:`theme`,children:[(0,N.jsx)(uf,{children:(0,N.jsx)(sr,{children:(0,N.jsx)(cf,{})})}),(0,N.jsx)(lf,{})]})}));export{fc as $,kl as A,zr as At,Zc as B,Gl as C,$r as Ct,J as D,Kr as Dt,Kl as E,qr as Et,bl as F,ze as Ft,_c as G,Kc as H,nl as I,Sc as J,xc as K,tl as L,El as M,Mr as Mt,wl as N,Ar as Nt,Ol as O,Wr as Ot,Tl as P,Or as Pt,gc as Q,Qc as R,Hl as S,ei as St,Y as T,Zr as Tt,Jc as U,Xc as V,Yc as W,yc as X,bc as Y,hc as Z,nu as _,pi as _t,wd as a,Di as at,Xl as b,li as bt,Xu as c,Si as ct,cd as d,yi as dt,ji as et,hu as f,vi as ft,ru as g,mi as gt,lu as h,hi as ht,Id as i,ki as it,Sl as j,Ir as jt,Al as k,Hr as kt,Qu as l,xi as lt,ou as m,gi as mt,Ud as n,wi as nt,yd as o,Ti as ot,cu as p,_i as pt,vc as q,Ld as r,Oi as rt,Zu as s,Ei as st,Gd as t,Ai as tt,$u as u,bi as ut,eu as v,fi as vt,ql as w,Qr as wt,Jl as x,ti as xt,Ql as y,di as yt,Gc as z};
|