@jonathanleelx/meddle 0.5.0-beta.2 → 0.5.0-beta.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/CONFIG_STRUCTURE.md +8 -2
  2. package/README.md +2 -0
  3. package/bin/commands/mock/add.js +33 -4
  4. package/bin/commands/mock/delete.js +8 -1
  5. package/bin/commands/mock/index.js +8 -4
  6. package/bin/commands/mock/list.js +1 -0
  7. package/bin/commands/mock/toggle.js +8 -1
  8. package/bin/commands/mock/update.js +31 -5
  9. package/bin/commands/route/active.js +6 -2
  10. package/bin/commands/route/add.js +12 -2
  11. package/bin/commands/route/create.js +8 -1
  12. package/bin/commands/route/delete.js +12 -2
  13. package/bin/commands/route/update.js +12 -2
  14. package/bin/commands/update.js +4 -0
  15. package/bin/lib/file-access.js +68 -25
  16. package/bin/lib/output.js +20 -1
  17. package/bin/lib/proxy-detect.js +99 -20
  18. package/bin/lib/update-check.js +67 -6
  19. package/dist/core/custom-plugin-loader.d.ts.map +1 -1
  20. package/dist/core/custom-plugin-loader.js +2 -0
  21. package/dist/core/custom-plugin-loader.js.map +1 -1
  22. package/dist/core/h2-pool.d.ts +1 -0
  23. package/dist/core/h2-pool.d.ts.map +1 -1
  24. package/dist/core/h2-pool.js +79 -23
  25. package/dist/core/h2-pool.js.map +1 -1
  26. package/dist/core/mock-handler.d.ts +40 -0
  27. package/dist/core/mock-handler.d.ts.map +1 -1
  28. package/dist/core/mock-handler.js +453 -28
  29. package/dist/core/mock-handler.js.map +1 -1
  30. package/dist/core/mock-utils.d.ts +58 -0
  31. package/dist/core/mock-utils.d.ts.map +1 -0
  32. package/dist/core/mock-utils.js +167 -0
  33. package/dist/core/mock-utils.js.map +1 -0
  34. package/dist/core/plugin-bootstrap-runner.d.ts +1 -0
  35. package/dist/core/plugin-bootstrap-runner.d.ts.map +1 -1
  36. package/dist/core/plugin-bootstrap-runner.js +37 -1
  37. package/dist/core/plugin-bootstrap-runner.js.map +1 -1
  38. package/dist/core/plugin-intercept.d.ts.map +1 -1
  39. package/dist/core/plugin-intercept.js +1 -0
  40. package/dist/core/plugin-intercept.js.map +1 -1
  41. package/dist/core/plugin-source.d.ts +24 -0
  42. package/dist/core/plugin-source.d.ts.map +1 -0
  43. package/dist/core/plugin-source.js +47 -0
  44. package/dist/core/plugin-source.js.map +1 -0
  45. package/dist/core/types.d.ts +13 -1
  46. package/dist/core/types.d.ts.map +1 -1
  47. package/dist/helpers.d.ts +8 -1
  48. package/dist/helpers.d.ts.map +1 -1
  49. package/dist/helpers.js +22 -5
  50. package/dist/helpers.js.map +1 -1
  51. package/dist/plugins/builtin/mock-plugin.d.ts.map +1 -1
  52. package/dist/plugins/builtin/mock-plugin.js +6 -5
  53. package/dist/plugins/builtin/mock-plugin.js.map +1 -1
  54. package/dist/server/agent/tools.d.ts.map +1 -1
  55. package/dist/server/agent/tools.js +4 -0
  56. package/dist/server/agent/tools.js.map +1 -1
  57. package/dist/server/app-info.d.ts +19 -0
  58. package/dist/server/app-info.d.ts.map +1 -0
  59. package/dist/server/app-info.js +84 -0
  60. package/dist/server/app-info.js.map +1 -0
  61. package/dist/server/config.d.ts +1 -0
  62. package/dist/server/config.d.ts.map +1 -1
  63. package/dist/server/config.js +23 -3
  64. package/dist/server/config.js.map +1 -1
  65. package/dist/server/health.d.ts.map +1 -1
  66. package/dist/server/health.js +8 -0
  67. package/dist/server/health.js.map +1 -1
  68. package/dist/server/index.d.ts +15 -0
  69. package/dist/server/index.d.ts.map +1 -1
  70. package/dist/server/index.js +2 -0
  71. package/dist/server/index.js.map +1 -1
  72. package/dist/server/mocks.d.ts +23 -0
  73. package/dist/server/mocks.d.ts.map +1 -1
  74. package/dist/server/mocks.js +108 -13
  75. package/dist/server/mocks.js.map +1 -1
  76. package/dist/server/plugins.d.ts.map +1 -1
  77. package/dist/server/plugins.js +56 -11
  78. package/dist/server/plugins.js.map +1 -1
  79. package/dist/server/rule-files.d.ts +53 -0
  80. package/dist/server/rule-files.d.ts.map +1 -1
  81. package/dist/server/rule-files.js +281 -30
  82. package/dist/server/rule-files.js.map +1 -1
  83. package/index.js +26 -5
  84. package/mcp-server.js +3 -0
  85. package/package.json +3 -2
  86. package/plugins/builtin/mock-plugin.ts +9 -5
  87. package/web/dist/assets/alert-BmsRCcSL.js +1 -0
  88. package/web/dist/assets/arrow-right-BNum_060.js +1 -0
  89. package/web/dist/assets/{body-diff-view-D7dCWajG.js → body-diff-view-ByCHr9bv.js} +2 -2
  90. package/web/dist/assets/button-BFNlGZ5p.js +1 -0
  91. package/web/dist/assets/check-BkfHQ6re.js +1 -0
  92. package/web/dist/assets/checkbox-v2kzp7K8.js +1 -0
  93. package/web/dist/assets/chevron-down-DHwUtL4O.js +1 -0
  94. package/web/dist/assets/{circle-alert-Q8cZk9Rv.js → circle-alert-zMagrFuI.js} +1 -1
  95. package/web/dist/assets/{circle-x-C9USji_R.js → circle-x-BEkinhez.js} +1 -1
  96. package/web/dist/assets/code-DD-AYxxu.js +1 -0
  97. package/web/dist/assets/{copy-BYjq1hdN.js → copy-BRnscYy1.js} +1 -1
  98. package/web/dist/assets/detail-panel-CO_7xRlW.js +4 -0
  99. package/web/dist/assets/{dist-D5Dj17P8.js → dist-BCvvYbmI.js} +1 -1
  100. package/web/dist/assets/dist-BNcjMpca.js +1 -0
  101. package/web/dist/assets/{dist-Bb9TeEub.js → dist-C-E2R2jk.js} +1 -1
  102. package/web/dist/assets/{dist-C6eaYCUo.js → dist-CFZ4xMSF.js} +1 -1
  103. package/web/dist/assets/{dist-C5nMErq8.js → dist-CRmX_NvH.js} +1 -1
  104. package/web/dist/assets/dist-DD7AvbXP.js +1 -0
  105. package/web/dist/assets/{dist-Cn0y0IRn.js → dist-LiAcI8CK.js} +1 -1
  106. package/web/dist/assets/dist-UcOFuoN0.js +5 -0
  107. package/web/dist/assets/{dist-B8XUKgXe.js → dist-YM3jbhT-.js} +1 -1
  108. package/web/dist/assets/editor-pane-actions-DN-pxFsl.js +1 -0
  109. package/web/dist/assets/es2015-CRmLuA2o.js +41 -0
  110. package/web/dist/assets/{global-panel-shell-R-EZQRhs.js → global-panel-shell-dKKTLNpP.js} +4 -4
  111. package/web/dist/assets/health-panel-CUEWcU8g.js +1 -0
  112. package/web/dist/assets/index-B9-_OFNJ.js +18 -0
  113. package/web/dist/assets/index-D9jGD_NA.css +2 -0
  114. package/web/dist/assets/{mobile-proxy-panel-Dxz-7iYx.js → mobile-proxy-panel-smm4Pg7o.js} +6 -6
  115. package/web/dist/assets/mock-config-BA0GNr6q.js +1 -0
  116. package/web/dist/assets/mock-editor-panel-ttVorhGI.js +20 -0
  117. package/web/dist/assets/mocks-file-missing-note-DBYZjOpC.js +1 -0
  118. package/web/dist/assets/monaco-editor-DH2CE6FN.js +11 -0
  119. package/web/dist/assets/pane-split-40_YQZ0-.js +1 -0
  120. package/web/dist/assets/panel-heading-BaLG_KAE.js +1 -0
  121. package/web/dist/assets/{pencil-line-Cqe41E4h.js → pencil-line-CEZ7D-de.js} +1 -1
  122. package/web/dist/assets/plugin-code-editor-B2Sc5Ngy.js +2 -0
  123. package/web/dist/assets/plugin-config-nnVWs8jW.js +2 -0
  124. package/web/dist/assets/plugin-generator-B2CAEqPa.js +2 -0
  125. package/web/dist/assets/plugin-test-dialog-BU0As6z0.js +7 -0
  126. package/web/dist/assets/plus-ixZQRprm.js +1 -0
  127. package/web/dist/assets/{refresh-cw-CG3HaiQT.js → refresh-cw-BfLoHqg5.js} +1 -1
  128. package/web/dist/assets/rotate-ccw-CRguJya4.js +1 -0
  129. package/web/dist/assets/route-preview-Do3jsXLI.js +1 -0
  130. package/web/dist/assets/{rule-ai-assistant-panel-CNL1O0GY.js → rule-ai-assistant-panel-g-UkLb_B.js} +2 -2
  131. package/web/dist/assets/rule-config-Bzw8J0q1.js +15 -0
  132. package/web/dist/assets/rule-overview-panel-DIBRGnrb.js +1 -0
  133. package/web/dist/assets/{server-Cpj4KNwN.js → server-eYXq3PbE.js} +1 -1
  134. package/web/dist/assets/settings-panel-CrvG4M_b.js +1 -0
  135. package/web/dist/assets/{shield-check-OqUmVLQt.js → shield-check-hQXjdfZ7.js} +1 -1
  136. package/web/dist/assets/smartphone-D4Q7cQfm.js +1 -0
  137. package/web/dist/assets/switch-DpLnRvOJ.js +1 -0
  138. package/web/dist/assets/{syntax-highlight-BHsSDUha.js → syntax-highlight-EJCxGikd.js} +1 -1
  139. package/web/dist/assets/table-2-DvGHhMm4.js +1 -0
  140. package/web/dist/assets/table-C3mgEjkP.js +1 -0
  141. package/web/dist/assets/textarea-BjWF0pk4.js +1 -0
  142. package/web/dist/assets/{wand-sparkles-wkul5vje.js → wand-sparkles-DDGjzjnX.js} +1 -1
  143. package/web/dist/assets/{wifi-D9M35Ajj.js → wifi-QkTcTrED.js} +1 -1
  144. package/web/dist/assets/{zap-Djo4cgux.js → zap-CEVoVkAg.js} +1 -1
  145. package/web/dist/index.html +17 -12
  146. package/web/dist/assets/alert-Bve02Ufr.js +0 -1
  147. package/web/dist/assets/arrow-right-B4Mrlj2-.js +0 -1
  148. package/web/dist/assets/button-BTToMaBW.js +0 -1
  149. package/web/dist/assets/checkbox-DK9f9Mxu.js +0 -1
  150. package/web/dist/assets/chevron-down-CPngAx4M.js +0 -1
  151. package/web/dist/assets/chevron-right-V1DGIDbL.js +0 -1
  152. package/web/dist/assets/code-5_eJ_XpJ.js +0 -1
  153. package/web/dist/assets/code-fixer-IRTVs-a6.js +0 -20
  154. package/web/dist/assets/detail-panel--2r_Fgpi.js +0 -4
  155. package/web/dist/assets/dist-CxdY_A67.js +0 -5
  156. package/web/dist/assets/es2015-CfXu88Y7.js +0 -41
  157. package/web/dist/assets/file-system-access-DK7FI6pN.js +0 -1
  158. package/web/dist/assets/health-panel-CKt2-Gkj.js +0 -1
  159. package/web/dist/assets/index-DhzkcDnh.js +0 -18
  160. package/web/dist/assets/index-PcoCj3ST.css +0 -2
  161. package/web/dist/assets/mock-config-84LSNP6M.js +0 -1
  162. package/web/dist/assets/mock-editor-panel-RJ1abekr.js +0 -1
  163. package/web/dist/assets/monaco-editor-CbL970eS.js +0 -11
  164. package/web/dist/assets/plugin-code-editor-DfLc4JdP.js +0 -2
  165. package/web/dist/assets/plugin-config-CT-u4XYw.js +0 -1
  166. package/web/dist/assets/plugin-generator-CyBK9FuM.js +0 -2
  167. package/web/dist/assets/plugin-test-dialog-B-NF0sGH.js +0 -7
  168. package/web/dist/assets/plus-tVxSydJ8.js +0 -1
  169. package/web/dist/assets/rotate-ccw-CAYM6Vv0.js +0 -1
  170. package/web/dist/assets/route-preview-C8nW9w7i.js +0 -1
  171. package/web/dist/assets/rule-config-DXfovZnm.js +0 -15
  172. package/web/dist/assets/select-DQ6s7CL8.js +0 -1
  173. package/web/dist/assets/settings-panel-BhXgMr_a.js +0 -1
  174. package/web/dist/assets/smartphone-DKeDuJTU.js +0 -1
  175. package/web/dist/assets/switch-C-Xk56TK.js +0 -1
  176. package/web/dist/assets/table-DymgLlcc.js +0 -1
  177. package/web/dist/assets/textarea-vuxJwU0x.js +0 -1
  178. /package/web/dist/assets/{ai-config-store-DQXVJVn_.js → ai-config-store-B_VpGvwx.js} +0 -0
  179. /package/web/dist/assets/{babel-DsprIpXZ.js → babel-D1quDdNt.js} +0 -0
  180. /package/web/dist/assets/{clipboard-Dz6MgwV-.js → clipboard-DUgC_tNv.js} +0 -0
  181. /package/web/dist/assets/{dist-DZJ9SMlJ.js → dist-Bq2klZ3g.js} +0 -0
  182. /package/web/dist/assets/{estree-BP7k0NIt.js → estree--Vq99DGn.js} +0 -0
  183. /package/web/dist/assets/{html-6FIWbqxX.js → html-D2PZBPnP.js} +0 -0
  184. /package/web/dist/assets/{postcss-Dnf30fQU.js → postcss-DfIslWug.js} +0 -0
  185. /package/web/dist/assets/{standalone-CjxtLKw-.js → standalone-D-fjaAIs.js} +0 -0
@@ -0,0 +1,41 @@
1
+ import{c as e,d as t,o as n,p as r}from"./button-BFNlGZ5p.js";import{o as i}from"./dist-CFZ4xMSF.js";import{t as a}from"./dist-C-E2R2jk.js";var o=r(t(),1),s=e(),c=`focusScope.autoFocusOnMount`,l=`focusScope.autoFocusOnUnmount`,u={bubbles:!1,cancelable:!0},d=`FocusScope`,f=o.forwardRef((e,t)=>{let{loop:r=!1,trapped:d=!1,onMountAutoFocus:f,onUnmountAutoFocus:g,..._}=e,[v,x]=o.useState(null),S=a(f),w=a(g),T=o.useRef(null),E=n(t,e=>x(e)),D=o.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;o.useEffect(()=>{if(d){let e=function(e){if(D.paused||!v)return;let t=e.target;v.contains(t)?T.current=t:y(T.current,{select:!0})},t=function(e){if(D.paused||!v)return;let t=e.relatedTarget;t!==null&&(v.contains(t)||y(T.current,{select:!0}))},n=function(e){if(document.activeElement===document.body)for(let t of e)t.removedNodes.length>0&&y(v)};document.addEventListener(`focusin`,e),document.addEventListener(`focusout`,t);let r=new MutationObserver(n);return v&&r.observe(v,{childList:!0,subtree:!0}),()=>{document.removeEventListener(`focusin`,e),document.removeEventListener(`focusout`,t),r.disconnect()}}},[d,v,D.paused]),o.useEffect(()=>{if(v){b.add(D);let e=document.activeElement;if(!v.contains(e)){let t=new CustomEvent(c,u);v.addEventListener(c,S),v.dispatchEvent(t),t.defaultPrevented||(p(C(h(v)),{select:!0}),document.activeElement===e&&y(v))}return()=>{v.removeEventListener(c,S),setTimeout(()=>{let t=new CustomEvent(l,u);v.addEventListener(l,w),v.dispatchEvent(t),t.defaultPrevented||y(e??document.body,{select:!0}),v.removeEventListener(l,w),b.remove(D)},0)}}},[v,S,w,D]);let O=o.useCallback(e=>{if(!r&&!d||D.paused)return;let t=e.key===`Tab`&&!e.altKey&&!e.ctrlKey&&!e.metaKey,n=document.activeElement;if(t&&n){let t=e.currentTarget,[i,a]=m(t);i&&a?!e.shiftKey&&n===a?(e.preventDefault(),r&&y(i,{select:!0})):e.shiftKey&&n===i&&(e.preventDefault(),r&&y(a,{select:!0})):n===t&&e.preventDefault()}},[r,d,D.paused]);return(0,s.jsx)(i.div,{tabIndex:-1,..._,ref:E,onKeyDown:O})});f.displayName=d;function p(e,{select:t=!1}={}){let n=document.activeElement;for(let r of e)if(y(r,{select:t}),document.activeElement!==n)return}function m(e){let t=h(e);return[g(t,e),g(t.reverse(),e)]}function h(e){let t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>{let t=e.tagName===`INPUT`&&e.type===`hidden`;return e.disabled||e.hidden||t?NodeFilter.FILTER_SKIP:e.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function g(e,t){for(let n of e)if(!_(n,{upTo:t}))return n}function _(e,{upTo:t}){if(getComputedStyle(e).visibility===`hidden`)return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display===`none`)return!0;e=e.parentElement}return!1}function v(e){return e instanceof HTMLInputElement&&`select`in e}function y(e,{select:t=!1}={}){if(e&&e.focus){let n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&v(e)&&t&&e.select()}}var b=x();function x(){let e=[];return{add(t){let n=e[0];t!==n&&n?.pause(),e=S(e,t),e.unshift(t)},remove(t){e=S(e,t),e[0]?.resume()}}}function S(e,t){let n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function C(e){return e.filter(e=>e.tagName!==`A`)}var w=0;function T(){o.useEffect(()=>{let e=document.querySelectorAll(`[data-radix-focus-guard]`);return document.body.insertAdjacentElement(`afterbegin`,e[0]??E()),document.body.insertAdjacentElement(`beforeend`,e[1]??E()),w++,()=>{w===1&&document.querySelectorAll(`[data-radix-focus-guard]`).forEach(e=>e.remove()),w--}},[])}function E(){let e=document.createElement(`span`);return e.setAttribute(`data-radix-focus-guard`,``),e.tabIndex=0,e.style.outline=`none`,e.style.opacity=`0`,e.style.position=`fixed`,e.style.pointerEvents=`none`,e}var D=function(){return D=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n],t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},D.apply(this,arguments)};function O(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols==`function`)for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n}function ee(e,t,n){if(n||arguments.length===2)for(var r=0,i=t.length,a;r<i;r++)(a||!(r in t))&&(a||=Array.prototype.slice.call(t,0,r),a[r]=t[r]);return e.concat(a||Array.prototype.slice.call(t))}var k=`right-scroll-bar-position`,A=`width-before-scroll-bar`,te=`with-scroll-bars-hidden`,ne=`--removed-body-scroll-bar-size`;function j(e,t){return typeof e==`function`?e(t):e&&(e.current=t),e}function re(e,t){var n=(0,o.useState)(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(e){var t=n.value;t!==e&&(n.value=e,n.callback(e,t))}}}})[0];return n.callback=t,n.facade}var ie=typeof window<`u`?o.useLayoutEffect:o.useEffect,M=new WeakMap;function ae(e,t){var n=re(t||null,function(t){return e.forEach(function(e){return j(e,t)})});return ie(function(){var t=M.get(n);if(t){var r=new Set(t),i=new Set(e),a=n.current;r.forEach(function(e){i.has(e)||j(e,null)}),i.forEach(function(e){r.has(e)||j(e,a)})}M.set(n,e)},[e]),n}function oe(e){return e}function se(e,t){t===void 0&&(t=oe);var n=[],r=!1;return{read:function(){if(r)throw Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(e){var i=t(e,r);return n.push(i),function(){n=n.filter(function(e){return e!==i})}},assignSyncMedium:function(e){for(r=!0;n.length;){var t=n;n=[],t.forEach(e)}n={push:function(t){return e(t)},filter:function(){return n}}},assignMedium:function(e){r=!0;var t=[];if(n.length){var i=n;n=[],i.forEach(e),t=n}var a=function(){var n=t;t=[],n.forEach(e)},o=function(){return Promise.resolve().then(a)};o(),n={push:function(e){t.push(e),o()},filter:function(e){return t=t.filter(e),n}}}}}function ce(e){e===void 0&&(e={});var t=se(null);return t.options=D({async:!0,ssr:!1},e),t}var N=function(e){var t=e.sideCar,n=O(e,[`sideCar`]);if(!t)throw Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw Error(`Sidecar medium not found`);return o.createElement(r,D({},n))};N.isSideCarExport=!0;function le(e,t){return e.useMedium(t),N}var P=ce(),F=function(){},I=o.forwardRef(function(e,t){var n=o.useRef(null),r=o.useState({onScrollCapture:F,onWheelCapture:F,onTouchMoveCapture:F}),i=r[0],a=r[1],s=e.forwardProps,c=e.children,l=e.className,u=e.removeScrollBar,d=e.enabled,f=e.shards,p=e.sideCar,m=e.noRelative,h=e.noIsolation,g=e.inert,_=e.allowPinchZoom,v=e.as,y=v===void 0?`div`:v,b=e.gapMode,x=O(e,[`forwardProps`,`children`,`className`,`removeScrollBar`,`enabled`,`shards`,`sideCar`,`noRelative`,`noIsolation`,`inert`,`allowPinchZoom`,`as`,`gapMode`]),S=p,C=ae([n,t]),w=D(D({},x),i);return o.createElement(o.Fragment,null,d&&o.createElement(S,{sideCar:P,removeScrollBar:u,shards:f,noRelative:m,noIsolation:h,inert:g,setCallbacks:a,allowPinchZoom:!!_,lockRef:n,gapMode:b}),s?o.cloneElement(o.Children.only(c),D(D({},w),{ref:C})):o.createElement(y,D({},w,{className:l,ref:C}),c))});I.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},I.classNames={fullWidth:A,zeroRight:k};var L,ue=function(){if(L)return L;if(typeof __webpack_nonce__<`u`)return __webpack_nonce__};function de(){if(!document)return null;var e=document.createElement(`style`);e.type=`text/css`;var t=ue();return t&&e.setAttribute(`nonce`,t),e}function fe(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function pe(e){(document.head||document.getElementsByTagName(`head`)[0]).appendChild(e)}var me=function(){var e=0,t=null;return{add:function(n){e==0&&(t=de())&&(fe(t,n),pe(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},he=function(){var e=me();return function(t,n){o.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},R=function(){var e=he();return function(t){var n=t.styles,r=t.dynamic;return e(n,r),null}},ge={left:0,top:0,right:0,gap:0},z=function(e){return parseInt(e||``,10)||0},_e=function(e){var t=window.getComputedStyle(document.body),n=t[e===`padding`?`paddingLeft`:`marginLeft`],r=t[e===`padding`?`paddingTop`:`marginTop`],i=t[e===`padding`?`paddingRight`:`marginRight`];return[z(n),z(r),z(i)]},ve=function(e){if(e===void 0&&(e=`margin`),typeof window>`u`)return ge;var t=_e(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},ye=R(),B=`data-scroll-locked`,be=function(e,t,n,r){var i=e.left,a=e.top,o=e.right,s=e.gap;return n===void 0&&(n=`margin`),`
2
+ .${te} {
3
+ overflow: hidden ${r};
4
+ padding-right: ${s}px ${r};
5
+ }
6
+ body[${B}] {
7
+ overflow: hidden ${r};
8
+ overscroll-behavior: contain;
9
+ ${[t&&`position: relative ${r};`,n===`margin`&&`
10
+ padding-left: ${i}px;
11
+ padding-top: ${a}px;
12
+ padding-right: ${o}px;
13
+ margin-left:0;
14
+ margin-top:0;
15
+ margin-right: ${s}px ${r};
16
+ `,n===`padding`&&`padding-right: ${s}px ${r};`].filter(Boolean).join(``)}
17
+ }
18
+
19
+ .${k} {
20
+ right: ${s}px ${r};
21
+ }
22
+
23
+ .${A} {
24
+ margin-right: ${s}px ${r};
25
+ }
26
+
27
+ .${k} .${k} {
28
+ right: 0 ${r};
29
+ }
30
+
31
+ .${A} .${A} {
32
+ margin-right: 0 ${r};
33
+ }
34
+
35
+ body[${B}] {
36
+ ${ne}: ${s}px;
37
+ }
38
+ `},V=function(){var e=parseInt(document.body.getAttribute(`data-scroll-locked`)||`0`,10);return isFinite(e)?e:0},xe=function(){o.useEffect(function(){return document.body.setAttribute(B,(V()+1).toString()),function(){var e=V()-1;e<=0?document.body.removeAttribute(B):document.body.setAttribute(B,e.toString())}},[])},Se=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,i=r===void 0?`margin`:r;xe();var a=o.useMemo(function(){return ve(i)},[i]);return o.createElement(ye,{styles:be(a,!t,i,n?``:`!important`)})},H=!1;if(typeof window<`u`)try{var U=Object.defineProperty({},`passive`,{get:function(){return H=!0,!0}});window.addEventListener(`test`,U,U),window.removeEventListener(`test`,U,U)}catch{H=!1}var W=H?{passive:!1}:!1,Ce=function(e){return e.tagName===`TEXTAREA`},G=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!==`hidden`&&!(n.overflowY===n.overflowX&&!Ce(e)&&n[t]===`visible`)},we=function(e){return G(e,`overflowY`)},Te=function(e){return G(e,`overflowX`)},K=function(e,t){var n=t.ownerDocument,r=t;do{if(typeof ShadowRoot<`u`&&r instanceof ShadowRoot&&(r=r.host),q(e,r)){var i=Oe(e,r);if(i[1]>i[2])return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Ee=function(e){return[e.scrollTop,e.scrollHeight,e.clientHeight]},De=function(e){return[e.scrollLeft,e.scrollWidth,e.clientWidth]},q=function(e,t){return e===`v`?we(t):Te(t)},Oe=function(e,t){return e===`v`?Ee(t):De(t)},ke=function(e,t){return e===`h`&&t===`rtl`?-1:1},Ae=function(e,t,n,r,i){var a=ke(e,window.getComputedStyle(t).direction),o=a*r,s=n.target,c=t.contains(s),l=!1,u=o>0,d=0,f=0;do{if(!s)break;var p=Oe(e,s),m=p[0],h=p[1]-p[2]-a*m;(m||h)&&q(e,s)&&(d+=h,f+=m);var g=s.parentNode;s=g&&g.nodeType===Node.DOCUMENT_FRAGMENT_NODE?g.host:g}while(!c&&s!==document.body||c&&(t.contains(s)||t===s));return(u&&(i&&Math.abs(d)<1||!i&&o>d)||!u&&(i&&Math.abs(f)<1||!i&&-o>f))&&(l=!0),l},J=function(e){return`changedTouches`in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},je=function(e){return[e.deltaX,e.deltaY]},Me=function(e){return e&&`current`in e?e.current:e},Ne=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Pe=function(e){return`
39
+ .block-interactivity-${e} {pointer-events: none;}
40
+ .allow-interactivity-${e} {pointer-events: all;}
41
+ `},Fe=0,Y=[];function Ie(e){var t=o.useRef([]),n=o.useRef([0,0]),r=o.useRef(),i=o.useState(Fe++)[0],a=o.useState(R)[0],s=o.useRef(e);o.useEffect(function(){s.current=e},[e]),o.useEffect(function(){if(e.inert){document.body.classList.add(`block-interactivity-${i}`);var t=ee([e.lockRef.current],(e.shards||[]).map(Me),!0).filter(Boolean);return t.forEach(function(e){return e.classList.add(`allow-interactivity-${i}`)}),function(){document.body.classList.remove(`block-interactivity-${i}`),t.forEach(function(e){return e.classList.remove(`allow-interactivity-${i}`)})}}},[e.inert,e.lockRef.current,e.shards]);var c=o.useCallback(function(e,t){if(`touches`in e&&e.touches.length===2||e.type===`wheel`&&e.ctrlKey)return!s.current.allowPinchZoom;var i=J(e),a=n.current,o=`deltaX`in e?e.deltaX:a[0]-i[0],c=`deltaY`in e?e.deltaY:a[1]-i[1],l,u=e.target,d=Math.abs(o)>Math.abs(c)?`h`:`v`;if(`touches`in e&&d===`h`&&u.type===`range`)return!1;var f=window.getSelection(),p=f&&f.anchorNode;if(p&&(p===u||p.contains(u)))return!1;var m=K(d,u);if(!m)return!0;if(m?l=d:(l=d===`v`?`h`:`v`,m=K(d,u)),!m)return!1;if(!r.current&&`changedTouches`in e&&(o||c)&&(r.current=l),!l)return!0;var h=r.current||l;return Ae(h,t,e,h===`h`?o:c,!0)},[]),l=o.useCallback(function(e){var n=e;if(!(!Y.length||Y[Y.length-1]!==a)){var r=`deltaY`in n?je(n):J(n),i=t.current.filter(function(e){return e.name===n.type&&(e.target===n.target||n.target===e.shadowParent)&&Ne(e.delta,r)})[0];if(i&&i.should){n.cancelable&&n.preventDefault();return}if(!i){var o=(s.current.shards||[]).map(Me).filter(Boolean).filter(function(e){return e.contains(n.target)});(o.length>0?c(n,o[0]):!s.current.noIsolation)&&n.cancelable&&n.preventDefault()}}},[]),u=o.useCallback(function(e,n,r,i){var a={name:e,delta:n,target:r,should:i,shadowParent:Le(r)};t.current.push(a),setTimeout(function(){t.current=t.current.filter(function(e){return e!==a})},1)},[]),d=o.useCallback(function(e){n.current=J(e),r.current=void 0},[]),f=o.useCallback(function(t){u(t.type,je(t),t.target,c(t,e.lockRef.current))},[]),p=o.useCallback(function(t){u(t.type,J(t),t.target,c(t,e.lockRef.current))},[]);o.useEffect(function(){return Y.push(a),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:p}),document.addEventListener(`wheel`,l,W),document.addEventListener(`touchmove`,l,W),document.addEventListener(`touchstart`,d,W),function(){Y=Y.filter(function(e){return e!==a}),document.removeEventListener(`wheel`,l,W),document.removeEventListener(`touchmove`,l,W),document.removeEventListener(`touchstart`,d,W)}},[]);var m=e.removeScrollBar,h=e.inert;return o.createElement(o.Fragment,null,h?o.createElement(a,{styles:Pe(i)}):null,m?o.createElement(Se,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Le(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}var Re=le(P,Ie),ze=o.forwardRef(function(e,t){return o.createElement(I,D({},e,{ref:t,sideCar:Re}))});ze.classNames=I.classNames;var Be=function(e){return typeof document>`u`?null:(Array.isArray(e)?e[0]:e).ownerDocument.body},X=new WeakMap,Z=new WeakMap,Q={},$=0,Ve=function(e){return e&&(e.host||Ve(e.parentNode))},He=function(e,t){return t.map(function(t){if(e.contains(t))return t;var n=Ve(t);return n&&e.contains(n)?n:(console.error(`aria-hidden`,t,`in not contained inside`,e,`. Doing nothing`),null)}).filter(function(e){return!!e})},Ue=function(e,t,n,r){var i=He(t,Array.isArray(e)?e:[e]);Q[n]||(Q[n]=new WeakMap);var a=Q[n],o=[],s=new Set,c=new Set(i),l=function(e){!e||s.has(e)||(s.add(e),l(e.parentNode))};i.forEach(l);var u=function(e){!e||c.has(e)||Array.prototype.forEach.call(e.children,function(e){if(s.has(e))u(e);else try{var t=e.getAttribute(r),i=t!==null&&t!==`false`,c=(X.get(e)||0)+1,l=(a.get(e)||0)+1;X.set(e,c),a.set(e,l),o.push(e),c===1&&i&&Z.set(e,!0),l===1&&e.setAttribute(n,`true`),i||e.setAttribute(r,`true`)}catch(t){console.error(`aria-hidden: cannot operate on `,e,t)}})};return u(t),s.clear(),$++,function(){o.forEach(function(e){var t=X.get(e)-1,i=a.get(e)-1;X.set(e,t),a.set(e,i),t||(Z.has(e)||e.removeAttribute(r),Z.delete(e)),i||e.removeAttribute(n)}),$--,$||(X=new WeakMap,X=new WeakMap,Z=new WeakMap,Q={})}},We=function(e,t,n){n===void 0&&(n=`data-aria-hidden`);var r=Array.from(Array.isArray(e)?e:[e]),i=t||Be(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll(`[aria-live], script`))),Ue(r,i,n,`aria-hidden`)):function(){return null}};export{f as i,ze as n,T as r,We as t};
@@ -1,6 +1,6 @@
1
- import{a as e,f as t,l as n,n as r,t as i,u as a}from"./button-BTToMaBW.js";import"./dist-C6eaYCUo.js";import{t as o}from"./circle-alert-Q8cZk9Rv.js";import{a as s,c,i as l,n as u,o as d,r as f,s as p}from"./dist-CxdY_A67.js";import"./es2015-CfXu88Y7.js";import{i as m,o as h,r as g}from"./ai-config-store-DQXVJVn_.js";import{A as _,Q as v,dt as y,ht as b,ot as x,pt as S,t as C,z as w}from"./index-DhzkcDnh.js";var T=n(`arrow-left`,[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]),E=n(`maximize-2`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`m21 3-7 7`,key:`1l2asr`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M9 21H3v-6`,key:`wtvkvv`}]]),D=n(`minimize-2`,[[`path`,{d:`m14 10 7-7`,key:`oa77jy`}],[`path`,{d:`M20 10h-6V4`,key:`mjg0md`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M4 14h6v6`,key:`rmj7iw`}]]),O=t(a(),1);function k(){let e=g(),t=m(e);return t?{...e,provider:t.provider,apiKey:t.apiKey,baseUrl:t.baseUrl,model:t.model}:e}async function A(e){let t=await e.json();if(!e.ok)throw Error(t.error||`请求失败: ${e.status}`);return t}function j(e){let t=e.split(`
1
+ import{c as e,d as t,l as n,p as r,t as i,u as a}from"./button-BFNlGZ5p.js";import"./dist-CFZ4xMSF.js";import{t as o}from"./circle-alert-zMagrFuI.js";import{a as s,c,i as l,n as u,o as d,r as f,s as p}from"./dist-UcOFuoN0.js";import"./es2015-CRmLuA2o.js";import{i as m,o as h,r as g}from"./ai-config-store-B_VpGvwx.js";import{Dt as _,Ft as v,It as y,nt as b,r as x,rt as S,yt as C}from"./index-B9-_OFNJ.js";var w=a(`arrow-left`,[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]),T=a(`command`,[[`path`,{d:`M15 6v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3`,key:`11bfej`}]]),E=a(`maximize-2`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`m21 3-7 7`,key:`1l2asr`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M9 21H3v-6`,key:`wtvkvv`}]]),D=a(`minimize-2`,[[`path`,{d:`m14 10 7-7`,key:`oa77jy`}],[`path`,{d:`M20 10h-6V4`,key:`mjg0md`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M4 14h6v6`,key:`rmj7iw`}]]),O=r(t(),1);function k(){let e=g(),t=m(e);return t?{...e,provider:t.provider,apiKey:t.apiKey,baseUrl:t.baseUrl,model:t.model}:e}async function A(e){let t=await e.json();if(!e.ok)throw Error(t.error||`请求失败: ${e.status}`);return t}function j(e){let t=e.split(`
2
2
  `);return{event:t.find(e=>e.startsWith(`event:`))?.slice(6).trim()||`message`,data:t.filter(e=>e.startsWith(`data:`)).map(e=>e.slice(5).trimStart()).join(`
3
- `)}}async function M(e,t={},n){let r=k();if(!h(r))throw Error(`请先在系统设置中启用并填写可用的 AI 配置。`);let i=await fetch(`/api/agent/chat-stream`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({message:e,aiConfig:r,...n?{conversationId:n}:{}})});if(!i.ok||!i.body)return A(i);let a=i.body.getReader(),o=new TextDecoder,s=``,c=e=>{let{event:n,data:r}=j(e);if(!r)return null;let i=JSON.parse(r);if(n===`start`)return t.onStart?.(),null;if(n===`delta`){let e=typeof i.delta==`string`?i.delta:``;return e&&t.onDelta?.(e),null}if(n===`error`)throw Error(typeof i.error==`string`?i.error:`AI 请求失败`);return n===`done`?i:null};for(;;){let{value:e,done:t}=await a.read();s+=o.decode(e||new Uint8Array,{stream:!t});let n=s.split(/\n\n/);s=n.pop()||``;for(let e of n){let t=c(e);if(t)return t}if(t)break}if(s.trim()){let e=c(s);if(e)return e}throw Error(`AI 流式响应未返回完成事件`)}async function N(e,t){return A(await fetch(`/api/agent/confirm`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({confirmationId:e,approved:t})}))}function P(e){return e.trim().toLowerCase()}function F(e,t){if(!e)return 1;let n=P(e),r=P(t);if(!n)return 1;if(!r)return 0;if(r===n)return 120;if(r.startsWith(n))return 100-Math.min(r.length-n.length,30);if(r.includes(n))return 80-Math.min(r.indexOf(n),30);let i=0,a=0;for(let e=0;e<r.length&&i<n.length;e++)n[i]===r[e]&&(i+=1,a+=4);return i===n.length?a:0}function I(e,t){let n=[t.title,t.description||``,t.section,...t.keywords||[]];return Math.max(...n.map(t=>F(e,t)))}function L(e,t){return(0,O.useMemo)(()=>{let n=e.map(e=>({command:e,score:I(t,e)})).filter(e=>e.score>0);return n.sort((e,t)=>e.command.disabled===t.command.disabled?t.score===e.score?e.command.title.localeCompare(t.command.title,`zh-Hans-CN`):t.score-e.score:e.command.disabled?1:-1),n.map(e=>e.command)},[e,t])}function R(){let e=(0,O.useContext)(C);if(!e)throw Error(`useGlobalPanel must be used inside GlobalPanelProvider`);return e}var z=e(),B={command:`w-[min(760px,calc(100vw-32px))] h-[min(760px,calc(100vh-48px))]`,md:`w-[min(760px,calc(100vw-32px))] h-[min(720px,calc(100vh-48px))]`,lg:`w-[min(1040px,calc(100vw-32px))] h-[min(780px,calc(100vh-48px))]`,xl:`w-[min(1240px,calc(100vw-32px))] h-[min(860px,calc(100vh-32px))]`,fullscreen:`w-[calc(100vw-32px)] h-[calc(100vh-32px)]`},V={md:{width:760,height:720},lg:{width:1040,height:780},xl:{width:1240,height:860},fullscreen:{width:1/0,height:1/0}};function H(){let e=typeof window>`u`?1280:window.innerWidth,t=typeof window>`u`?900:window.innerHeight,n=Math.max(320,e-32),r=Math.max(360,t-32);return{minWidth:Math.min(560,n),minHeight:Math.min(420,r),maxWidth:n,maxHeight:r}}function U(e){let t=H();return{width:Math.min(t.maxWidth,Math.max(t.minWidth,e.width)),height:Math.min(t.maxHeight,Math.max(t.minHeight,e.height))}}function W(e){let t=H(),n=V[e]||V.lg;return e===`fullscreen`?{width:t.maxWidth,height:t.maxHeight}:U(n)}function G(e){if(typeof window>`u`)return null;try{let t=window.localStorage.getItem(`global-panel-size:${e}`);if(!t)return null;let n=JSON.parse(t);return typeof n.width!=`number`||typeof n.height!=`number`?null:U({width:n.width,height:n.height})}catch{return null}}function K(e){let t=[],n=/(`[^`]+`|\*\*[^*]+\*\*)/g,r=0,i;for(;i=n.exec(e);){i.index>r&&t.push(e.slice(r,i.index));let n=i[0];n.startsWith("`")?t.push((0,z.jsx)(`code`,{className:`rounded bg-muted/70 px-1 py-0.5 font-mono text-[0.92em]`,children:n.slice(1,-1)},`${i.index}-code`)):t.push((0,z.jsx)(`strong`,{children:n.slice(2,-2)},`${i.index}-strong`)),r=i.index+n.length}return r<e.length&&t.push(e.slice(r)),t}function q(e){return/^\s*\|?\s*:?-{3,}:?\s*(\|\s*:?-{3,}:?\s*)+\|?\s*$/.test(e)}function J(e){return e.trim().replace(/^\|/,``).replace(/\|$/,``).split(`|`).map(e=>e.trim())}function Y({content:e}){let t=e.replace(/\r\n/g,`
3
+ `)}}async function M(e,t={},n){let r=k();if(!h(r))throw Error(`请先在系统设置中启用并填写可用的 AI 配置。`);let i=await fetch(`/api/agent/chat-stream`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({message:e,aiConfig:r,...n?{conversationId:n}:{}})});if(!i.ok||!i.body)return A(i);let a=i.body.getReader(),o=new TextDecoder,s=``,c=e=>{let{event:n,data:r}=j(e);if(!r)return null;let i=JSON.parse(r);if(n===`start`)return t.onStart?.(),null;if(n===`delta`){let e=typeof i.delta==`string`?i.delta:``;return e&&t.onDelta?.(e),null}if(n===`error`)throw Error(typeof i.error==`string`?i.error:`AI 请求失败`);return n===`done`?i:null};for(;;){let{value:e,done:t}=await a.read();s+=o.decode(e||new Uint8Array,{stream:!t});let n=s.split(/\n\n/);s=n.pop()||``;for(let e of n){let t=c(e);if(t)return t}if(t)break}if(s.trim()){let e=c(s);if(e)return e}throw Error(`AI 流式响应未返回完成事件`)}async function N(e,t){return A(await fetch(`/api/agent/confirm`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({confirmationId:e,approved:t})}))}function P(e){return e.trim().toLowerCase()}function F(e,t){if(!e)return 1;let n=P(e),r=P(t);if(!n)return 1;if(!r)return 0;if(r===n)return 120;if(r.startsWith(n))return 100-Math.min(r.length-n.length,30);if(r.includes(n))return 80-Math.min(r.indexOf(n),30);let i=0,a=0;for(let e=0;e<r.length&&i<n.length;e++)n[i]===r[e]&&(i+=1,a+=4);return i===n.length?a:0}function I(e,t){let n=[t.title,t.description||``,t.section,...t.keywords||[]];return Math.max(...n.map(t=>F(e,t)))}function L(e,t){return(0,O.useMemo)(()=>{let n=e.map(e=>({command:e,score:I(t,e)})).filter(e=>e.score>0);return n.sort((e,t)=>e.command.disabled===t.command.disabled?t.score===e.score?e.command.title.localeCompare(t.command.title,`zh-Hans-CN`):t.score-e.score:e.command.disabled?1:-1),n.map(e=>e.command)},[e,t])}function R(){let e=(0,O.useContext)(x);if(!e)throw Error(`useGlobalPanel must be used inside GlobalPanelProvider`);return e}var z=e(),B={command:`w-[min(760px,calc(100vw-32px))] h-[min(760px,calc(100vh-48px))]`,md:`w-[min(760px,calc(100vw-32px))] h-[min(720px,calc(100vh-48px))]`,lg:`w-[min(1040px,calc(100vw-32px))] h-[min(780px,calc(100vh-48px))]`,xl:`w-[min(1240px,calc(100vw-32px))] h-[min(860px,calc(100vh-32px))]`,fullscreen:`w-[calc(100vw-32px)] h-[calc(100vh-32px)]`},V={md:{width:760,height:720},lg:{width:1040,height:780},xl:{width:1240,height:860},fullscreen:{width:1/0,height:1/0}};function H(){let e=typeof window>`u`?1280:window.innerWidth,t=typeof window>`u`?900:window.innerHeight,n=Math.max(320,e-32),r=Math.max(360,t-32);return{minWidth:Math.min(560,n),minHeight:Math.min(420,r),maxWidth:n,maxHeight:r}}function U(e){let t=H();return{width:Math.min(t.maxWidth,Math.max(t.minWidth,e.width)),height:Math.min(t.maxHeight,Math.max(t.minHeight,e.height))}}function W(e){let t=H(),n=V[e]||V.lg;return e===`fullscreen`?{width:t.maxWidth,height:t.maxHeight}:U(n)}function G(e){if(typeof window>`u`)return null;try{let t=window.localStorage.getItem(`global-panel-size:${e}`);if(!t)return null;let n=JSON.parse(t);return typeof n.width!=`number`||typeof n.height!=`number`?null:U({width:n.width,height:n.height})}catch{return null}}function K(e){let t=[],n=/(`[^`]+`|\*\*[^*]+\*\*)/g,r=0,i;for(;i=n.exec(e);){i.index>r&&t.push(e.slice(r,i.index));let n=i[0];n.startsWith("`")?t.push((0,z.jsx)(`code`,{className:`rounded bg-muted/70 px-1 py-0.5 font-mono text-[0.92em]`,children:n.slice(1,-1)},`${i.index}-code`)):t.push((0,z.jsx)(`strong`,{children:n.slice(2,-2)},`${i.index}-strong`)),r=i.index+n.length}return r<e.length&&t.push(e.slice(r)),t}function q(e){return/^\s*\|?\s*:?-{3,}:?\s*(\|\s*:?-{3,}:?\s*)+\|?\s*$/.test(e)}function J(e){return e.trim().replace(/^\|/,``).replace(/\|$/,``).split(`|`).map(e=>e.trim())}function Y({content:e}){let t=e.replace(/\r\n/g,`
4
4
  `).split(`
5
- `),n=[],i=0;for(;i<t.length;){let e=t[i].trim();if(!e){i+=1;continue}let a=e.match(/^```(\w+)?/);if(a){let e=a[1],r=[];for(i+=1;i<t.length&&!t[i].trim().startsWith("```");)r.push(t[i]),i+=1;i+=1,n.push((0,z.jsxs)(`div`,{className:`overflow-hidden rounded-md border bg-muted/45`,children:[e&&(0,z.jsx)(`div`,{className:`border-b bg-background/45 px-3 py-1 text-[11px] uppercase tracking-wide text-muted-foreground`,children:e}),(0,z.jsx)(`pre`,{className:`max-h-64 overflow-auto p-3 text-xs leading-5`,children:(0,z.jsx)(`code`,{children:r.join(`
6
- `)})})]},`code-${i}`));continue}let o=e.match(/^(#{1,4})\s+(.+)$/);if(o){let e=o[1].length,t=r(`font-semibold leading-6 text-foreground`,e<=2?`mt-2 text-sm`:`text-[13px]`),a=K(o[2]);n.push(e===1?(0,z.jsx)(`h3`,{className:t,children:a},`heading-${i}`):e===2?(0,z.jsx)(`h4`,{className:t,children:a},`heading-${i}`):(0,z.jsx)(`h5`,{className:t,children:a},`heading-${i}`)),i+=1;continue}if(/^---+$/.test(e)){n.push((0,z.jsx)(`div`,{className:`h-px bg-border/70`},`hr-${i}`)),i+=1;continue}if(e.includes(`|`)&&i+1<t.length&&q(t[i+1])){let r=J(e),a=[];for(i+=2;i<t.length&&t[i].trim().includes(`|`);)a.push(J(t[i])),i+=1;n.push((0,z.jsx)(`div`,{className:`overflow-auto rounded-md border`,children:(0,z.jsxs)(`table`,{className:`w-full min-w-max border-collapse text-xs`,children:[(0,z.jsx)(`thead`,{className:`bg-muted/50 text-muted-foreground`,children:(0,z.jsx)(`tr`,{children:r.map((e,t)=>(0,z.jsx)(`th`,{className:`border-b px-2 py-1.5 text-left font-medium`,children:K(e)},`${e}-${t}`))})}),(0,z.jsx)(`tbody`,{children:a.map((e,t)=>(0,z.jsx)(`tr`,{className:`border-b last:border-0`,children:e.map((e,n)=>(0,z.jsx)(`td`,{className:`px-2 py-1.5 align-top`,children:K(e)},`${t}-${n}`))},t))})]})},`table-${i}`));continue}if(/^[-*]\s+/.test(e)||/^\d+\.\s+/.test(e)){let a=/^\d+\.\s+/.test(e),o=[];for(;i<t.length;){let e=t[i].trim(),n=a?e.match(/^\d+\.\s+(.+)$/):e.match(/^[-*]\s+(.+)$/);if(!n)break;o.push(n[1]),i+=1}let s=a?`ol`:`ul`;n.push((0,z.jsx)(s,{className:r(`space-y-1 pl-5`,a?`list-decimal`:`list-disc`),children:o.map((e,t)=>(0,z.jsx)(`li`,{children:K(e)},t))},`list-${i}`));continue}let s=[e];for(i+=1;i<t.length;){let e=t[i].trim();if(!e||e.startsWith("```")||/^#{1,4}\s+/.test(e)||/^[-*]\s+/.test(e)||/^\d+\.\s+/.test(e)||/^---+$/.test(e)||e.includes(`|`)&&i+1<t.length&&q(t[i+1]))break;s.push(e),i+=1}n.push((0,z.jsx)(`p`,{className:`leading-6 text-foreground/90`,children:K(s.join(` `))},`p-${i}`))}return(0,z.jsx)(`div`,{className:`agent-markdown-content space-y-3 text-sm`,children:n})}function X({commands:e}){let t=R(),[n,a]=(0,O.useState)(``),[s,c]=(0,O.useState)(0),[l,u]=(0,O.useState)(null),[d,f]=(0,O.useState)(null),[p,m]=(0,O.useState)(null),[h,g]=(0,O.useState)(!1),[C,T]=(0,O.useState)(null),[E,D]=(0,O.useState)(null),[k,A]=(0,O.useState)([]),[j,P]=(0,O.useState)(``),[F,I]=(0,O.useState)(null),B=(0,O.useRef)(null),V=(0,O.useRef)(null),H=(0,O.useRef)(null),U=(0,O.useRef)(null),W=L(e,n),G=n.trim(),K=!!(p||d||h||k.length>0);(0,O.useEffect)(()=>{let e=requestAnimationFrame(()=>B.current?.focus());return()=>cancelAnimationFrame(e)},[]),(0,O.useEffect)(()=>{c(0)},[n]),(0,O.useEffect)(()=>{let e=V.current;!e||!K||(e.scrollTop=e.scrollHeight)},[p,h,d?.message,k,K]);let q=W[s];(0,O.useLayoutEffect)(()=>{let e=H.current,t=U.current;if(!e||!t)return;let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();n.top<r.top+12?t.scrollTop-=r.top+12-n.top:n.bottom>r.bottom-12&&(t.scrollTop+=n.bottom-(r.bottom-12))},[s,W]);let J=(0,O.useMemo)(()=>{let e=new Map;return W.forEach(t=>{e.has(t.section)||e.set(t.section,[]),e.get(t.section)?.push(t)}),Array.from(e.entries())},[W]),X=async e=>{if(!(!e||e.disabled)&&!(e.confirm&&!window.confirm(e.confirm))){u(e.id);try{await e.run(),e.closeOnRun!==!1&&t.close()}finally{u(null)}}},Z=async(e,t)=>{if(!e||h)return;g(!0),m(null),f(null),I(e),t||(D(null),A([]));let n=``;try{let r=await M(e,{onDelta:e=>{n+=e,f({runId:`streaming`,message:n,pendingConfirmations:[],toolResults:[],conversationId:t||``})}},t);f(r),D(r.conversationId),A(t=>[...t,{userMessage:e,aiMessage:r.message}])}catch(e){m(e.message)}finally{g(!1),I(null)}},Q=async()=>{let e=j.trim();!e||h||!E||(P(``),await Z(e,E))},$=async(e,t)=>{T(e),m(null);try{let n=await N(e,t),r=(n.result&&typeof n.result==`object`?n.result:null)?.message||n.message;f(t=>({runId:t?.runId||e,message:r,pendingConfirmations:[],toolResults:n.result?[n.result]:[],conversationId:t?.conversationId||``})),A(e=>e.length===0?e:e.map((t,n)=>n===e.length-1?{...t,aiMessage:r}:t))}catch(e){m(e.message)}finally{T(null)}};return(0,z.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,z.jsxs)(`div`,{className:`global-panel-topbar flex items-center gap-3 border-b px-4 py-3`,children:[(0,z.jsx)(v,{className:`h-4 w-4 text-muted-foreground`}),(0,z.jsx)(_,{ref:B,value:n,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`ArrowDown`?(e.preventDefault(),c(e=>Math.min(e+1,Math.max(W.length-1,0)))):e.key===`ArrowUp`?(e.preventDefault(),c(e=>Math.max(e-1,0))):e.key===`Enter`?(e.preventDefault(),q?X(q):G&&Z(G)):e.key===`Escape`&&!n&&t.close()},placeholder:`搜索命令,或直接描述你想让 AI 完成的操作...`,className:`h-9 border-0 bg-transparent px-0 shadow-none focus-visible:ring-0 dark:bg-transparent`}),(0,z.jsx)(w,{variant:`outline`,className:`hidden shrink-0 text-[11px] font-normal sm:inline-flex`,children:`⌘K`})]}),(0,z.jsxs)(`div`,{ref:U,className:`min-h-0 flex-1 overflow-y-auto`,children:[G&&(0,z.jsx)(`div`,{className:`p-3 pb-0`,children:(0,z.jsxs)(`button`,{type:`button`,className:`global-command-action flex w-full items-center gap-3 rounded-md border px-3 py-2 text-left text-sm transition-colors disabled:cursor-not-allowed disabled:opacity-60`,disabled:h,onClick:()=>void Z(G),children:[(0,z.jsx)(`div`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-md border bg-background/55 backdrop-blur`,children:h?(0,z.jsx)(x,{className:`h-4 w-4 animate-spin`}):(0,z.jsx)(b,{className:`h-4 w-4`})}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`div`,{className:`font-medium`,children:`让 AI 处理`}),(0,z.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:G})]})]})}),(p||d||h||k.length>0)&&(0,z.jsx)(`div`,{className:`p-3 pb-0`,children:(0,z.jsxs)(`div`,{className:r(`overflow-hidden rounded-md border text-sm`,p?`border-destructive/40 bg-destructive/5`:`bg-background/35 backdrop-blur`),children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 border-b bg-background/35 px-3 py-2`,children:[p?(0,z.jsx)(o,{className:`h-4 w-4 shrink-0 text-destructive`}):h?(0,z.jsx)(x,{className:`h-4 w-4 shrink-0 animate-spin text-muted-foreground`}):(0,z.jsx)(S,{className:`h-4 w-4 shrink-0 text-emerald-500`}),(0,z.jsx)(`div`,{className:`min-w-0 flex-1 font-medium`,children:p?`AI 请求失败`:h?`AI 正在处理`:`AI 响应`})]}),(0,z.jsx)(`div`,{ref:V,className:`max-h-[min(520px,calc(100vh-220px))] overflow-y-auto overscroll-contain`,children:(0,z.jsxs)(`div`,{className:`px-3 py-3`,children:[p&&k.length===0?(0,z.jsx)(`div`,{className:`whitespace-pre-wrap break-words leading-6 text-destructive`,children:p}):null,k.map((e,t)=>(0,z.jsxs)(`div`,{className:r(t>0&&`mt-4 border-t pt-4`),children:[(0,z.jsx)(`div`,{className:`mb-1 text-xs font-medium text-muted-foreground`,children:`你`}),(0,z.jsx)(`div`,{className:`mb-3 whitespace-pre-wrap break-words leading-6 text-foreground/90`,children:e.userMessage}),(0,z.jsx)(`div`,{className:`mb-1 text-xs font-medium text-muted-foreground`,children:`AI`}),(0,z.jsx)(Y,{content:e.aiMessage})]},t)),F&&(0,z.jsxs)(`div`,{className:r(k.length>0&&`mt-4 border-t pt-4`),children:[(0,z.jsx)(`div`,{className:`mb-1 text-xs font-medium text-muted-foreground`,children:`你`}),(0,z.jsx)(`div`,{className:`mb-3 whitespace-pre-wrap break-words leading-6 text-foreground/90`,children:F}),(0,z.jsx)(`div`,{className:`mb-1 text-xs font-medium text-muted-foreground`,children:`AI`}),h&&!d?.message?(0,z.jsx)(`div`,{className:`leading-6 text-muted-foreground`,children:`正在分析你的请求并调用可用工具...`}):d?.message?(0,z.jsx)(Y,{content:d.message}):null,p?(0,z.jsx)(`div`,{className:`whitespace-pre-wrap break-words leading-6 text-destructive`,children:p}):null]}),d?.pendingConfirmations.map(e=>(0,z.jsxs)(`div`,{className:`mt-3 rounded-md border bg-background/55 p-3 backdrop-blur`,children:[(0,z.jsx)(`div`,{className:`font-medium`,children:e.summary}),e.diff&&(0,z.jsx)(`pre`,{className:`mt-2 max-h-40 overflow-auto rounded border bg-muted/40 p-2 text-xs leading-5 text-muted-foreground`,children:e.diff}),(0,z.jsxs)(`div`,{className:`mt-3 flex justify-end gap-2`,children:[(0,z.jsx)(i,{variant:`ghost`,size:`sm`,disabled:C===e.id,onClick:()=>void $(e.id,!1),children:`取消`}),(0,z.jsxs)(i,{size:`sm`,disabled:C===e.id,onClick:()=>void $(e.id,!0),children:[C===e.id?(0,z.jsx)(x,{className:`mr-1 h-3.5 w-3.5 animate-spin`}):null,`确认执行`]})]})]},e.id))]})}),E&&!h&&d&&d.pendingConfirmations.length===0&&(0,z.jsx)(`div`,{className:`border-t px-3 py-2`,children:(0,z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,z.jsx)(_,{value:j,onChange:e=>P(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Q())},placeholder:`继续对话...`,className:`h-8 text-sm`}),(0,z.jsx)(i,{size:`sm`,disabled:!j.trim()||h,onClick:()=>void Q(),children:`发送`})]})})]})}),W.length===0&&!K?(0,z.jsxs)(`div`,{className:`flex h-64 flex-col items-center justify-center gap-2 px-6 text-center text-muted-foreground`,children:[(0,z.jsx)(y,{className:`h-8 w-8 opacity-50`}),(0,z.jsx)(`div`,{className:`text-sm`,children:`没有找到匹配的操作`})]}):W.length>0?(0,z.jsx)(`div`,{className:`space-y-4 p-3`,children:J.map(([e,t])=>(0,z.jsxs)(`div`,{className:`space-y-1`,children:[(0,z.jsx)(`div`,{className:`px-2 py-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:e}),t.map(e=>{let t=W.findIndex(t=>t.id===e.id),n=e.icon,i=t===s,a=l===e.id;return(0,z.jsxs)(`button`,{ref:i?H:void 0,type:`button`,"data-selected":i?`true`:void 0,className:r(`flex w-full items-center gap-3 rounded-md px-2 py-2 text-left text-sm transition-colors`,i?`bg-accent/70 text-accent-foreground shadow-sm`:`hover:bg-accent/45`,e.disabled&&`cursor-not-allowed opacity-50`,e.danger&&!e.disabled&&`text-destructive`),onMouseEnter:()=>c(t),onClick:()=>void X(e),disabled:a,children:[(0,z.jsx)(`div`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-md border bg-background/55 backdrop-blur`,children:a?(0,z.jsx)(x,{className:`h-4 w-4 animate-spin`}):n?(0,z.jsx)(n,{className:`h-4 w-4`}):(0,z.jsx)(y,{className:`h-4 w-4`})}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`div`,{className:`truncate font-medium`,children:e.title}),(e.description||e.disabledReason)&&(0,z.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:e.disabled&&e.disabledReason||e.description})]}),e.shortcut&&(0,z.jsx)(w,{variant:`secondary`,className:`shrink-0 text-[10px] font-normal`,children:e.shortcut})]},e.id)})]},e))}):null]})]})}function Z({commands:e,renderPanel:t}){let n=R(),a=n.currentRoute,o=a?.size||`command`,m=a?.id,h=a?.size,[g,_]=(0,O.useState)(null),[v,y]=(0,O.useState)(!1),[b,x]=(0,O.useState)(!1),S=(0,O.useRef)(null);(0,O.useEffect)(()=>{let e=window.requestAnimationFrame(()=>{if(!m){_(null),y(!1),x(!1);return}_(G(m)||W(h||`lg`)),y(h===`fullscreen`),x(!1)});return()=>window.cancelAnimationFrame(e)},[m,h]),(0,O.useEffect)(()=>{if(!m)return;let e=()=>{_(e=>e&&U(e))};return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[m]);let C=e=>{!a||v||typeof window>`u`||window.localStorage.setItem(`global-panel-size:${a.id}`,JSON.stringify(e))},w=e=>{if(!a||!g||v)return;e.preventDefault(),x(!0);let t=e.pointerId,n=e.clientX,r=e.clientY,i=g,o=e.currentTarget;o.setPointerCapture(t);let s=e=>{_(U({width:i.width+(e.clientX-n)*2,height:i.height+(e.clientY-r)}))},c=()=>{o.hasPointerCapture(t)&&o.releasePointerCapture(t),window.removeEventListener(`pointermove`,s),window.removeEventListener(`pointerup`,c),window.removeEventListener(`pointercancel`,c),x(!1),_(e=>(e&&C(e),e))};window.addEventListener(`pointermove`,s),window.addEventListener(`pointerup`,c),window.addEventListener(`pointercancel`,c)},k=()=>{if(!(!a||!g)){if(v){_(U(S.current||G(a.id)||W(a.size||`lg`))),y(!1);return}S.current=g,_(W(`fullscreen`)),y(!0)}},A=a&&g?{width:`${g.width}px`,height:`${g.height}px`}:void 0;return(0,z.jsx)(d,{open:n.open,onOpenChange:e=>{e||n.close()},children:(0,z.jsxs)(s,{children:[(0,z.jsx)(l,{className:`global-panel-overlay fixed inset-0 z-[80]`}),(0,z.jsx)(u,{style:A,className:r(`global-panel-content global-panel-surface fixed left-1/2 top-4 z-[81] flex flex-col overflow-hidden rounded-lg border outline-none`,a&&!b&&`transition-[width,height] duration-200 ease-out`,!a&&B[o]),children:a?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:`global-panel-topbar flex items-center gap-2 border-b px-4 py-3`,children:[n.stack.length>1&&(0,z.jsx)(i,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:n.back,title:`返回上一级`,children:(0,z.jsx)(T,{className:`h-4 w-4`})}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(p,{className:`truncate text-sm font-semibold`,children:a.title}),a.description&&(0,z.jsx)(f,{className:`truncate text-xs text-muted-foreground`,children:a.description})]}),(0,z.jsx)(i,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:k,title:v?`还原尺寸`:`最大化`,children:v?(0,z.jsx)(D,{className:`h-4 w-4`}):(0,z.jsx)(E,{className:`h-4 w-4`})}),(0,z.jsx)(i,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:n.close,title:`关闭`,children:(0,z.jsx)(c,{className:`h-4 w-4`})})]}),(0,z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:t(a)}),!v&&(0,z.jsx)(`button`,{type:`button`,"aria-label":`调整面板尺寸`,title:`拖拽调整面板尺寸`,className:`absolute bottom-0 right-0 h-6 w-6 cursor-nwse-resize rounded-tl-md text-muted-foreground/70 transition-colors hover:bg-accent hover:text-foreground`,onPointerDown:w,children:(0,z.jsx)(`span`,{className:`pointer-events-none absolute bottom-1 right-1 h-3 w-3 border-b border-r border-current`})})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(p,{className:`sr-only`,children:`全局操作面板`}),(0,z.jsx)(f,{className:`sr-only`,children:`搜索并执行 Meddle 的页面、设置和功能操作。`}),(0,z.jsx)(X,{commands:e})]})})]})})}export{Z as GlobalPanelShell};
5
+ `),r=[],i=0;for(;i<t.length;){let e=t[i].trim();if(!e){i+=1;continue}let a=e.match(/^```(\w+)?/);if(a){let e=a[1],n=[];for(i+=1;i<t.length&&!t[i].trim().startsWith("```");)n.push(t[i]),i+=1;i+=1,r.push((0,z.jsxs)(`div`,{className:`overflow-hidden rounded-md border bg-muted/45`,children:[e&&(0,z.jsx)(`div`,{className:`border-b bg-background/45 px-3 py-1 text-[11px] uppercase tracking-wide text-muted-foreground`,children:e}),(0,z.jsx)(`pre`,{className:`max-h-64 overflow-auto p-3 text-xs leading-5`,children:(0,z.jsx)(`code`,{children:n.join(`
6
+ `)})})]},`code-${i}`));continue}let o=e.match(/^(#{1,4})\s+(.+)$/);if(o){let e=o[1].length,t=n(`font-semibold leading-6 text-foreground`,e<=2?`mt-2 text-sm`:`text-[13px]`),a=K(o[2]);r.push(e===1?(0,z.jsx)(`h3`,{className:t,children:a},`heading-${i}`):e===2?(0,z.jsx)(`h4`,{className:t,children:a},`heading-${i}`):(0,z.jsx)(`h5`,{className:t,children:a},`heading-${i}`)),i+=1;continue}if(/^---+$/.test(e)){r.push((0,z.jsx)(`div`,{className:`h-px bg-border/70`},`hr-${i}`)),i+=1;continue}if(e.includes(`|`)&&i+1<t.length&&q(t[i+1])){let n=J(e),a=[];for(i+=2;i<t.length&&t[i].trim().includes(`|`);)a.push(J(t[i])),i+=1;r.push((0,z.jsx)(`div`,{className:`overflow-auto rounded-md border`,children:(0,z.jsxs)(`table`,{className:`w-full min-w-max border-collapse text-xs`,children:[(0,z.jsx)(`thead`,{className:`bg-muted/50 text-muted-foreground`,children:(0,z.jsx)(`tr`,{children:n.map((e,t)=>(0,z.jsx)(`th`,{className:`border-b px-2 py-1.5 text-left font-medium`,children:K(e)},`${e}-${t}`))})}),(0,z.jsx)(`tbody`,{children:a.map((e,t)=>(0,z.jsx)(`tr`,{className:`border-b last:border-0`,children:e.map((e,n)=>(0,z.jsx)(`td`,{className:`px-2 py-1.5 align-top`,children:K(e)},`${t}-${n}`))},t))})]})},`table-${i}`));continue}if(/^[-*]\s+/.test(e)||/^\d+\.\s+/.test(e)){let a=/^\d+\.\s+/.test(e),o=[];for(;i<t.length;){let e=t[i].trim(),n=a?e.match(/^\d+\.\s+(.+)$/):e.match(/^[-*]\s+(.+)$/);if(!n)break;o.push(n[1]),i+=1}let s=a?`ol`:`ul`;r.push((0,z.jsx)(s,{className:n(`space-y-1 pl-5`,a?`list-decimal`:`list-disc`),children:o.map((e,t)=>(0,z.jsx)(`li`,{children:K(e)},t))},`list-${i}`));continue}let s=[e];for(i+=1;i<t.length;){let e=t[i].trim();if(!e||e.startsWith("```")||/^#{1,4}\s+/.test(e)||/^[-*]\s+/.test(e)||/^\d+\.\s+/.test(e)||/^---+$/.test(e)||e.includes(`|`)&&i+1<t.length&&q(t[i+1]))break;s.push(e),i+=1}r.push((0,z.jsx)(`p`,{className:`leading-6 text-foreground/90`,children:K(s.join(` `))},`p-${i}`))}return(0,z.jsx)(`div`,{className:`agent-markdown-content space-y-3 text-sm`,children:r})}function X({commands:e}){let t=R(),[r,a]=(0,O.useState)(``),[s,c]=(0,O.useState)(0),[l,u]=(0,O.useState)(null),[d,f]=(0,O.useState)(null),[p,m]=(0,O.useState)(null),[h,g]=(0,O.useState)(!1),[x,w]=(0,O.useState)(null),[E,D]=(0,O.useState)(null),[k,A]=(0,O.useState)([]),[j,P]=(0,O.useState)(``),[F,I]=(0,O.useState)(null),B=(0,O.useRef)(null),V=(0,O.useRef)(null),H=(0,O.useRef)(null),U=(0,O.useRef)(null),W=L(e,r),G=r.trim(),K=!!(p||d||h||k.length>0);(0,O.useEffect)(()=>{let e=requestAnimationFrame(()=>B.current?.focus());return()=>cancelAnimationFrame(e)},[]),(0,O.useEffect)(()=>{c(0)},[r]),(0,O.useEffect)(()=>{let e=V.current;!e||!K||(e.scrollTop=e.scrollHeight)},[p,h,d?.message,k,K]);let q=W[s];(0,O.useLayoutEffect)(()=>{let e=H.current,t=U.current;if(!e||!t)return;let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();n.top<r.top+12?t.scrollTop-=r.top+12-n.top:n.bottom>r.bottom-12&&(t.scrollTop+=n.bottom-(r.bottom-12))},[s,W]);let J=(0,O.useMemo)(()=>{let e=new Map;return W.forEach(t=>{e.has(t.section)||e.set(t.section,[]),e.get(t.section)?.push(t)}),Array.from(e.entries())},[W]),X=async e=>{if(!(!e||e.disabled)&&!(e.confirm&&!window.confirm(e.confirm))){u(e.id);try{await e.run(),e.closeOnRun!==!1&&t.close()}finally{u(null)}}},Z=async(e,t)=>{if(!e||h)return;g(!0),m(null),f(null),I(e),t||(D(null),A([]));let n=``;try{let r=await M(e,{onDelta:e=>{n+=e,f({runId:`streaming`,message:n,pendingConfirmations:[],toolResults:[],conversationId:t||``})}},t);f(r),D(r.conversationId),A(t=>[...t,{userMessage:e,aiMessage:r.message}])}catch(e){m(e.message)}finally{g(!1),I(null)}},Q=async()=>{let e=j.trim();!e||h||!E||(P(``),await Z(e,E))},$=async(e,t)=>{w(e),m(null);try{let n=await N(e,t),r=(n.result&&typeof n.result==`object`?n.result:null)?.message||n.message;f(t=>({runId:t?.runId||e,message:r,pendingConfirmations:[],toolResults:n.result?[n.result]:[],conversationId:t?.conversationId||``})),A(e=>e.length===0?e:e.map((t,n)=>n===e.length-1?{...t,aiMessage:r}:t))}catch(e){m(e.message)}finally{w(null)}};return(0,z.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,z.jsxs)(`div`,{className:`global-panel-topbar flex items-center gap-3 border-b px-4 py-3`,children:[(0,z.jsx)(C,{className:`h-4 w-4 text-muted-foreground`}),(0,z.jsx)(S,{ref:B,value:r,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`ArrowDown`?(e.preventDefault(),c(e=>Math.min(e+1,Math.max(W.length-1,0)))):e.key===`ArrowUp`?(e.preventDefault(),c(e=>Math.max(e-1,0))):e.key===`Enter`?(e.preventDefault(),q?X(q):G&&Z(G)):e.key===`Escape`&&!r&&t.close()},placeholder:`搜索命令,或直接描述你想让 AI 完成的操作...`,className:`h-9 border-0 bg-transparent px-0 shadow-none focus-visible:ring-0 dark:bg-transparent`}),(0,z.jsx)(b,{variant:`outline`,className:`hidden shrink-0 text-[11px] font-normal sm:inline-flex`,children:`⌘K`})]}),(0,z.jsxs)(`div`,{ref:U,className:`min-h-0 flex-1 overflow-y-auto`,children:[G&&(0,z.jsx)(`div`,{className:`p-3 pb-0`,children:(0,z.jsxs)(`button`,{type:`button`,className:`global-command-action flex w-full items-center gap-3 rounded-md border px-3 py-2 text-left text-sm transition-colors disabled:cursor-not-allowed disabled:opacity-60`,disabled:h,onClick:()=>void Z(G),children:[(0,z.jsx)(`div`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-md border bg-background/55 backdrop-blur`,children:h?(0,z.jsx)(_,{className:`h-4 w-4 animate-spin`}):(0,z.jsx)(y,{className:`h-4 w-4`})}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`div`,{className:`font-medium`,children:`让 AI 处理`}),(0,z.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:G})]})]})}),(p||d||h||k.length>0)&&(0,z.jsx)(`div`,{className:`p-3 pb-0`,children:(0,z.jsxs)(`div`,{className:n(`overflow-hidden rounded-md border text-sm`,p?`border-destructive/40 bg-destructive/5`:`bg-background/35 backdrop-blur`),children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 border-b bg-background/35 px-3 py-2`,children:[p?(0,z.jsx)(o,{className:`h-4 w-4 shrink-0 text-destructive`}):h?(0,z.jsx)(_,{className:`h-4 w-4 shrink-0 animate-spin text-muted-foreground`}):(0,z.jsx)(v,{className:`h-4 w-4 shrink-0 text-emerald-500`}),(0,z.jsx)(`div`,{className:`min-w-0 flex-1 font-medium`,children:p?`AI 请求失败`:h?`AI 正在处理`:`AI 响应`})]}),(0,z.jsx)(`div`,{ref:V,className:`max-h-[min(520px,calc(100vh-220px))] overflow-y-auto overscroll-contain`,children:(0,z.jsxs)(`div`,{className:`px-3 py-3`,children:[p&&k.length===0?(0,z.jsx)(`div`,{className:`whitespace-pre-wrap break-words leading-6 text-destructive`,children:p}):null,k.map((e,t)=>(0,z.jsxs)(`div`,{className:n(t>0&&`mt-4 border-t pt-4`),children:[(0,z.jsx)(`div`,{className:`mb-1 text-xs font-medium text-muted-foreground`,children:`你`}),(0,z.jsx)(`div`,{className:`mb-3 whitespace-pre-wrap break-words leading-6 text-foreground/90`,children:e.userMessage}),(0,z.jsx)(`div`,{className:`mb-1 text-xs font-medium text-muted-foreground`,children:`AI`}),(0,z.jsx)(Y,{content:e.aiMessage})]},t)),F&&(0,z.jsxs)(`div`,{className:n(k.length>0&&`mt-4 border-t pt-4`),children:[(0,z.jsx)(`div`,{className:`mb-1 text-xs font-medium text-muted-foreground`,children:`你`}),(0,z.jsx)(`div`,{className:`mb-3 whitespace-pre-wrap break-words leading-6 text-foreground/90`,children:F}),(0,z.jsx)(`div`,{className:`mb-1 text-xs font-medium text-muted-foreground`,children:`AI`}),h&&!d?.message?(0,z.jsx)(`div`,{className:`leading-6 text-muted-foreground`,children:`正在分析你的请求并调用可用工具...`}):d?.message?(0,z.jsx)(Y,{content:d.message}):null,p?(0,z.jsx)(`div`,{className:`whitespace-pre-wrap break-words leading-6 text-destructive`,children:p}):null]}),d?.pendingConfirmations.map(e=>(0,z.jsxs)(`div`,{className:`mt-3 rounded-md border bg-background/55 p-3 backdrop-blur`,children:[(0,z.jsx)(`div`,{className:`font-medium`,children:e.summary}),e.diff&&(0,z.jsx)(`pre`,{className:`mt-2 max-h-40 overflow-auto rounded border bg-muted/40 p-2 text-xs leading-5 text-muted-foreground`,children:e.diff}),(0,z.jsxs)(`div`,{className:`mt-3 flex justify-end gap-2`,children:[(0,z.jsx)(i,{variant:`ghost`,size:`sm`,disabled:x===e.id,onClick:()=>void $(e.id,!1),children:`取消`}),(0,z.jsxs)(i,{size:`sm`,disabled:x===e.id,onClick:()=>void $(e.id,!0),children:[x===e.id?(0,z.jsx)(_,{className:`mr-1 h-3.5 w-3.5 animate-spin`}):null,`确认执行`]})]})]},e.id))]})}),E&&!h&&d&&d.pendingConfirmations.length===0&&(0,z.jsx)(`div`,{className:`border-t px-3 py-2`,children:(0,z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,z.jsx)(S,{value:j,onChange:e=>P(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Q())},placeholder:`继续对话...`,className:`h-8 text-sm`}),(0,z.jsx)(i,{size:`sm`,disabled:!j.trim()||h,onClick:()=>void Q(),children:`发送`})]})})]})}),W.length===0&&!K?(0,z.jsxs)(`div`,{className:`flex h-64 flex-col items-center justify-center gap-2 px-6 text-center text-muted-foreground`,children:[(0,z.jsx)(T,{className:`h-8 w-8 opacity-50`}),(0,z.jsx)(`div`,{className:`text-sm`,children:`没有找到匹配的操作`})]}):W.length>0?(0,z.jsx)(`div`,{className:`space-y-4 p-3`,children:J.map(([e,t])=>(0,z.jsxs)(`div`,{className:`space-y-1`,children:[(0,z.jsx)(`div`,{className:`px-2 py-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:e}),t.map(e=>{let t=W.findIndex(t=>t.id===e.id),r=e.icon,i=t===s,a=l===e.id;return(0,z.jsxs)(`button`,{ref:i?H:void 0,type:`button`,"data-selected":i?`true`:void 0,className:n(`flex w-full items-center gap-3 rounded-md px-2 py-2 text-left text-sm transition-colors`,i?`bg-accent/70 text-accent-foreground shadow-sm`:`hover:bg-accent/45`,e.disabled&&`cursor-not-allowed opacity-50`,e.danger&&!e.disabled&&`text-destructive`),onMouseEnter:()=>c(t),onClick:()=>void X(e),disabled:a,children:[(0,z.jsx)(`div`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-md border bg-background/55 backdrop-blur`,children:a?(0,z.jsx)(_,{className:`h-4 w-4 animate-spin`}):r?(0,z.jsx)(r,{className:`h-4 w-4`}):(0,z.jsx)(T,{className:`h-4 w-4`})}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`div`,{className:`truncate font-medium`,children:e.title}),(e.description||e.disabledReason)&&(0,z.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:e.disabled&&e.disabledReason||e.description})]}),e.shortcut&&(0,z.jsx)(b,{variant:`secondary`,className:`shrink-0 text-[10px] font-normal`,children:e.shortcut})]},e.id)})]},e))}):null]})]})}function Z({commands:e,renderPanel:t}){let r=R(),a=r.currentRoute,o=a?.size||`command`,m=a?.id,h=a?.size,[g,_]=(0,O.useState)(null),[v,y]=(0,O.useState)(!1),[b,x]=(0,O.useState)(!1),S=(0,O.useRef)(null);(0,O.useEffect)(()=>{let e=window.requestAnimationFrame(()=>{if(!m){_(null),y(!1),x(!1);return}_(G(m)||W(h||`lg`)),y(h===`fullscreen`),x(!1)});return()=>window.cancelAnimationFrame(e)},[m,h]),(0,O.useEffect)(()=>{if(!m)return;let e=()=>{_(e=>e&&U(e))};return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[m]);let C=e=>{!a||v||typeof window>`u`||window.localStorage.setItem(`global-panel-size:${a.id}`,JSON.stringify(e))},T=e=>{if(!a||!g||v)return;e.preventDefault(),x(!0);let t=e.pointerId,n=e.clientX,r=e.clientY,i=g,o=e.currentTarget;o.setPointerCapture(t);let s=e=>{_(U({width:i.width+(e.clientX-n)*2,height:i.height+(e.clientY-r)}))},c=()=>{o.hasPointerCapture(t)&&o.releasePointerCapture(t),window.removeEventListener(`pointermove`,s),window.removeEventListener(`pointerup`,c),window.removeEventListener(`pointercancel`,c),x(!1),_(e=>(e&&C(e),e))};window.addEventListener(`pointermove`,s),window.addEventListener(`pointerup`,c),window.addEventListener(`pointercancel`,c)},k=()=>{if(!(!a||!g)){if(v){_(U(S.current||G(a.id)||W(a.size||`lg`))),y(!1);return}S.current=g,_(W(`fullscreen`)),y(!0)}},A=a&&g?{width:`${g.width}px`,height:`${g.height}px`}:void 0;return(0,z.jsx)(d,{open:r.open,onOpenChange:e=>{e||r.close()},children:(0,z.jsxs)(s,{children:[(0,z.jsx)(l,{className:`global-panel-overlay fixed inset-0 z-[80]`}),(0,z.jsx)(u,{style:A,className:n(`global-panel-content global-panel-surface fixed left-1/2 top-4 z-[81] flex flex-col overflow-hidden rounded-lg border outline-none`,a&&!b&&`transition-[width,height] duration-200 ease-out`,!a&&B[o]),children:a?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:`global-panel-topbar flex items-center gap-2 border-b px-4 py-3`,children:[r.stack.length>1&&(0,z.jsx)(i,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:r.back,title:`返回上一级`,children:(0,z.jsx)(w,{className:`h-4 w-4`})}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(p,{className:`truncate text-sm font-semibold`,children:a.title}),a.description&&(0,z.jsx)(f,{className:`truncate text-xs text-muted-foreground`,children:a.description})]}),(0,z.jsx)(i,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:k,title:v?`还原尺寸`:`最大化`,children:v?(0,z.jsx)(D,{className:`h-4 w-4`}):(0,z.jsx)(E,{className:`h-4 w-4`})}),(0,z.jsx)(i,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:r.close,title:`关闭`,children:(0,z.jsx)(c,{className:`h-4 w-4`})})]}),(0,z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:t(a)}),!v&&(0,z.jsx)(`button`,{type:`button`,"aria-label":`调整面板尺寸`,title:`拖拽调整面板尺寸`,className:`absolute bottom-0 right-0 h-6 w-6 cursor-nwse-resize rounded-tl-md text-muted-foreground/70 transition-colors hover:bg-accent hover:text-foreground`,onPointerDown:T,children:(0,z.jsx)(`span`,{className:`pointer-events-none absolute bottom-1 right-1 h-3 w-3 border-b border-r border-current`})})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(p,{className:`sr-only`,children:`全局操作面板`}),(0,z.jsx)(f,{className:`sr-only`,children:`搜索并执行 Meddle 的页面、设置和功能操作。`}),(0,z.jsx)(X,{commands:e})]})})]})})}export{Z as GlobalPanelShell};
@@ -0,0 +1 @@
1
+ import{c as e,d as t,l as n,p as r,t as i,u as a}from"./button-BFNlGZ5p.js";import"./dist-CFZ4xMSF.js";import{t as o}from"./circle-x-BEkinhez.js";import{n as s,t as c}from"./server-eYXq3PbE.js";import{t as l}from"./refresh-cw-BfLoHqg5.js";import{t as ee}from"./shield-check-hQXjdfZ7.js";import{t as u}from"./wifi-QkTcTrED.js";import{t as d}from"./switch-DpLnRvOJ.js";import{Ft as f,G as p,H as m,K as h,W as g,at as _,ct as v,dt as y,it as b,kt as te,lt as x,mt as ne,nt as S,ot as re,q as C,st as w,ut as T}from"./index-B9-_OFNJ.js";import{n as E,r as D,t as O}from"./alert-BmsRCcSL.js";import{a as k,i as A,n as j,o as M,r as N,t as P}from"./table-C3mgEjkP.js";var F=a(`cpu`,[[`path`,{d:`M12 20v2`,key:`1lh1kg`}],[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`M17 20v2`,key:`1rnc9c`}],[`path`,{d:`M17 2v2`,key:`11trls`}],[`path`,{d:`M2 12h2`,key:`1t8f8n`}],[`path`,{d:`M2 17h2`,key:`7oei6x`}],[`path`,{d:`M2 7h2`,key:`asdhe0`}],[`path`,{d:`M20 12h2`,key:`1q8mjw`}],[`path`,{d:`M20 17h2`,key:`1fpfkl`}],[`path`,{d:`M20 7h2`,key:`1o8tra`}],[`path`,{d:`M7 20v2`,key:`4gnj0m`}],[`path`,{d:`M7 2v2`,key:`1i4yhu`}],[`rect`,{x:`4`,y:`4`,width:`16`,height:`16`,rx:`2`,key:`1vbyd7`}],[`rect`,{x:`8`,y:`8`,width:`8`,height:`8`,rx:`1`,key:`z9xiuo`}]]),I=a(`gauge`,[[`path`,{d:`m12 14 4-4`,key:`9kzdfg`}],[`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`,key:`19p75a`}]]),L=a(`hard-drive`,[[`line`,{x1:`22`,x2:`2`,y1:`12`,y2:`12`,key:`1y58io`}],[`path`,{d:`M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z`,key:`oot6mr`}],[`line`,{x1:`6`,x2:`6.01`,y1:`16`,y2:`16`,key:`sgf278`}],[`line`,{x1:`10`,x2:`10.01`,y1:`16`,y2:`16`,key:`1l4acy`}]]),R=a(`network`,[[`rect`,{x:`16`,y:`16`,width:`6`,height:`6`,rx:`1`,key:`4q2zg0`}],[`rect`,{x:`2`,y:`16`,width:`6`,height:`6`,rx:`1`,key:`8cvhb9`}],[`rect`,{x:`9`,y:`2`,width:`6`,height:`6`,rx:`1`,key:`1egb70`}],[`path`,{d:`M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3`,key:`1jsf9p`}],[`path`,{d:`M12 12V8`,key:`2874zd`}]]),z=r(t(),1),B=e(),V={ok:`正常`,degraded:`降级`,critical:`严重`},ie={cpu:`CPU`,rss:`RSS 内存`,connections:`连接数`,mitmServers:`MITM 服务`,eventLoopDelay:`事件循环延迟`,fds:`文件描述符`};function H(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.generatedAt==`number`&&typeof t.status==`string`&&typeof t.pid==`number`&&typeof t.uptimeSec==`number`&&!!t.memory&&!!t.cpu&&!!t.connections&&!!t.mitmServers&&Array.isArray(t.checks)}async function U(){let e=await fetch(`/api/health`,{cache:`no-store`});if(!e.ok)throw Error(`健康接口返回 ${e.status}`);let t=await e.json();if(!H(t))throw Error(`健康接口返回格式不正确`);return t}function W(e){if(!Number.isFinite(e))return`-`;if(e<1024)return`${e} B`;let t=[`KB`,`MB`,`GB`,`TB`],n=e/1024,r=t[0];for(let e=1;e<t.length&&n>=1024;e+=1)n/=1024,r=t[e];return`${n>=10?n.toFixed(0):n.toFixed(1)} ${r}`}function G(e){if(!Number.isFinite(e)||e<0)return`-`;let t=Math.floor(e/86400),n=Math.floor(e%86400/3600),r=Math.floor(e%3600/60),i=Math.floor(e%60);return t>0?`${t}天 ${n}小时`:n>0?`${n}小时 ${r}分钟`:r>0?`${r}分钟 ${i}秒`:`${i}秒`}function K(e){return e?new Intl.DateTimeFormat(`zh-CN`,{month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1}).format(new Date(e)):`-`}function q(e,t){return t===`bytes`?W(e):t===`%`?`${e.toFixed(1)}%`:t===`ms`?`${e.toFixed(1)} ms`:String(e)}function J(e,t){return t===`bytes`?W(e):t===`%`?`${e}%`:t===`ms`?`${e} ms`:String(e)}function ae(e){if(!e||typeof e!=`object`)return null;let t=e;return Array.isArray(t.keys)?{windowMs:Number(t.windowMs)||0,maxPerWindow:Number(t.maxPerWindow)||0,keys:t.keys,suppressedTotal:Number(t.suppressedTotal)||0}:null}function Y({status:e}){return(0,B.jsxs)(S,{variant:e===`critical`?`destructive`:e===`degraded`?`secondary`:`default`,children:[e===`ok`?(0,B.jsx)(f,{}):e===`degraded`?(0,B.jsx)(y,{}):(0,B.jsx)(o,{}),V[e]]})}function oe({icon:e,label:t,value:n,detail:r}){return(0,B.jsxs)(_,{className:`gap-0 py-0 shadow-none`,children:[(0,B.jsx)(x,{className:`border-b px-[var(--ui-section-gap)] py-[var(--ui-section-gap)] [.border-b]:pb-[var(--ui-section-gap)]`,children:(0,B.jsxs)(T,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,B.jsx)(e,{}),t]})}),(0,B.jsxs)(w,{className:`flex flex-col gap-1 p-[var(--ui-page-padding)]`,children:[(0,B.jsx)(`div`,{className:`text-2xl font-semibold tracking-tight`,children:n}),(0,B.jsx)(`div`,{className:`min-h-4 truncate text-xs text-muted-foreground`,title:r,children:r})]})]})}function X({label:e,value:t}){return(0,B.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1 rounded-lg border bg-background p-[var(--ui-section-gap)]`,children:[(0,B.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e}),(0,B.jsx)(`span`,{className:`truncate text-sm font-medium`,title:t,children:t})]})}function se(){return(0,B.jsxs)(`div`,{className:`app-workspace-content`,"aria-label":`正在读取健康状态`,children:[(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,B.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,B.jsx)(b,{className:`h-7 w-40`}),(0,B.jsx)(b,{className:`h-4 w-64`})]}),(0,B.jsx)(b,{className:`h-8 w-28`})]}),(0,B.jsx)(`div`,{className:`grid gap-[var(--ui-section-gap)] md:grid-cols-2 xl:grid-cols-6`,children:Array.from({length:6}).map((e,t)=>(0,B.jsx)(b,{className:`h-32 w-full`},t))}),(0,B.jsx)(b,{className:`h-80 w-full`})]})}function Z(){let[e,t]=(0,z.useState)(null),[r,a]=(0,z.useState)(!0),[o,f]=(0,z.useState)(!1),[b,V]=(0,z.useState)(``),[H,Z]=(0,z.useState)(!0),Q=(0,z.useCallback)(async(e=!1)=>{e?f(!0):a(!0),V(``);try{t(await U())}catch(e){V(e instanceof Error?e.message:`无法读取健康状态`)}finally{a(!1),f(!1)}},[]);(0,z.useEffect)(()=>{Q()},[Q]),(0,z.useEffect)(()=>{if(!H)return;let e=window.setInterval(()=>{Q(!0)},5e3);return()=>window.clearInterval(e)},[H,Q]);let $=(0,z.useMemo)(()=>ae(e?.logs),[e]);if(r&&!e)return(0,B.jsx)(se,{});if(!e)return(0,B.jsxs)(`div`,{className:`app-workspace-content`,children:[(0,B.jsxs)(O,{variant:`destructive`,children:[(0,B.jsx)(D,{children:`加载失败`}),(0,B.jsx)(E,{children:b||`无法读取健康状态`})]}),(0,B.jsxs)(i,{variant:`outline`,size:`sm`,onClick:()=>void Q(),children:[(0,B.jsx)(l,{"data-icon":`inline-start`}),`重新检测`]})]});let ce=[{icon:F,label:`CPU`,value:`${e.cpu.percent.toFixed(1)}%`,detail:`${e.cpu.cores} 核 · load ${e.cpu.loadAverage.map(e=>e.toFixed(2)).join(` / `)}`},{icon:L,label:`RSS 内存`,value:W(e.memory.rss),detail:`Heap ${W(e.memory.heapUsed)} / ${W(e.memory.heapTotal)}`},{icon:R,label:`TCP 连接`,value:String(e.connections.total),detail:`代理 ${e.connections.proxySockets} · TLS ${e.connections.mitmTlsSockets} · WS ${e.connections.webSockets}`},{icon:c,label:`MITM 服务`,value:String(e.mitmServers.count),detail:`${e.mitmServers.activeSockets} 个活跃 socket`},{icon:ne,label:`文件描述符`,value:e.process.fdCount==null?`-`:String(e.process.fdCount),detail:`handles ${e.process.activeHandles??`-`} · requests ${e.process.activeRequests??`-`}`},{icon:I,label:`事件循环`,value:`${e.eventLoop.maxMs.toFixed(1)} ms`,detail:`mean ${e.eventLoop.meanMs.toFixed(1)} ms`}];return(0,B.jsxs)(`div`,{className:`meddle-thin-scroll app-workspace-content overflow-y-auto`,children:[(0,B.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,B.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,B.jsx)(`h2`,{className:`text-xl font-semibold tracking-tight`,children:`运行健康`}),(0,B.jsx)(Y,{status:e.status})]}),(0,B.jsxs)(`div`,{className:`flex flex-wrap gap-3 text-xs text-muted-foreground`,children:[(0,B.jsxs)(`span`,{children:[`PID `,e.pid]}),(0,B.jsxs)(`span`,{children:[`运行 `,G(e.uptimeSec)]}),(0,B.jsx)(`span`,{children:e.platform}),(0,B.jsxs)(`span`,{children:[`更新 `,K(e.generatedAt)]})]})]}),(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,B.jsxs)(`div`,{className:`flex h-8 items-center gap-2 rounded-md border bg-background px-3 text-sm`,children:[(0,B.jsx)(d,{checked:H,onCheckedChange:Z,"aria-label":`自动刷新健康信息`}),(0,B.jsx)(`span`,{children:`自动刷新`})]}),(0,B.jsxs)(i,{variant:`outline`,size:`sm`,onClick:()=>void Q(!0),disabled:o,children:[(0,B.jsx)(l,{"data-icon":`inline-start`,className:n(o&&`animate-spin`)}),`刷新`]})]})]}),b&&(0,B.jsxs)(O,{variant:`destructive`,children:[(0,B.jsx)(D,{children:`刷新失败`}),(0,B.jsx)(E,{children:b})]}),(0,B.jsx)(`div`,{className:`grid gap-[var(--ui-section-gap)] md:grid-cols-2 xl:grid-cols-6`,children:ce.map(e=>(0,B.jsx)(oe,{...e},e.label))}),(0,B.jsxs)(`div`,{className:`grid gap-[var(--ui-section-gap)] xl:grid-cols-[minmax(0,1.3fr)_minmax(360px,0.7fr)]`,children:[(0,B.jsxs)(_,{className:`gap-0 py-0 shadow-none`,children:[(0,B.jsxs)(x,{className:`border-b px-[var(--ui-section-gap)] py-[var(--ui-section-gap)] [.border-b]:pb-[var(--ui-section-gap)]`,children:[(0,B.jsxs)(T,{className:`flex items-center gap-2`,children:[(0,B.jsx)(te,{}),`健康检查`]}),(0,B.jsx)(v,{children:`阈值来自当前进程的 MEDDLE_WATCHDOG 配置。`})]}),(0,B.jsx)(w,{className:`p-0`,children:(0,B.jsxs)(P,{children:[(0,B.jsx)(k,{children:(0,B.jsxs)(M,{children:[(0,B.jsx)(A,{children:`项目`}),(0,B.jsx)(A,{children:`状态`}),(0,B.jsx)(A,{children:`当前值`}),(0,B.jsx)(A,{children:`阈值`})]})}),(0,B.jsx)(j,{children:e.checks.map(e=>(0,B.jsxs)(M,{children:[(0,B.jsx)(N,{className:`font-medium`,children:ie[e.name]||e.name}),(0,B.jsx)(N,{children:(0,B.jsx)(Y,{status:e.status})}),(0,B.jsx)(N,{children:q(e.value,e.unit)}),(0,B.jsx)(N,{className:`text-muted-foreground`,children:J(e.limit,e.unit)})]},e.name))})]})})]}),(0,B.jsxs)(_,{className:`gap-0 py-0 shadow-none`,children:[(0,B.jsxs)(x,{className:`border-b px-[var(--ui-section-gap)] py-[var(--ui-section-gap)] [.border-b]:pb-[var(--ui-section-gap)]`,children:[(0,B.jsxs)(T,{className:`flex items-center gap-2`,children:[(0,B.jsx)(ee,{}),`守护策略`]}),(0,B.jsx)(v,{children:`连续命中严重阈值后按策略处理。`}),(0,B.jsx)(re,{children:(0,B.jsx)(S,{variant:e.watchdog.config.enabled?`default`:`secondary`,children:e.watchdog.config.enabled?`已启用`:`已关闭`})})]}),(0,B.jsxs)(w,{className:`grid gap-[var(--ui-section-gap)] p-[var(--ui-page-padding)] sm:grid-cols-2`,children:[(0,B.jsx)(X,{label:`动作`,value:e.watchdog.config.action===`exit`?`退出重启`:`仅告警`}),(0,B.jsx)(X,{label:`检测间隔`,value:G(e.watchdog.config.intervalMs/1e3)}),(0,B.jsx)(X,{label:`最小运行时间`,value:G(e.watchdog.config.minUptimeMs/1e3)}),(0,B.jsx)(X,{label:`失败阈值`,value:`${e.watchdog.consecutiveFailures}/${e.watchdog.config.failureThreshold}`}),(0,B.jsx)(X,{label:`CPU 阈值`,value:`${e.watchdog.config.cpuPercent}%`}),(0,B.jsx)(X,{label:`RSS 阈值`,value:W(e.watchdog.config.rssBytes)}),(0,B.jsx)(X,{label:`连接阈值`,value:String(e.watchdog.config.connectionCount)}),(0,B.jsx)(X,{label:`FD 阈值`,value:String(e.watchdog.config.fdCount)}),e.watchdog.lastReason&&(0,B.jsx)(`div`,{className:`sm:col-span-2`,children:(0,B.jsxs)(O,{children:[(0,B.jsx)(y,{}),(0,B.jsx)(D,{children:`最近命中`}),(0,B.jsx)(E,{children:e.watchdog.lastReason})]})})]})]})]}),(0,B.jsxs)(`div`,{className:`grid gap-[var(--ui-section-gap)] xl:grid-cols-2`,children:[(0,B.jsxs)(_,{className:`gap-0 py-0 shadow-none`,children:[(0,B.jsxs)(x,{className:`border-b px-[var(--ui-section-gap)] py-[var(--ui-section-gap)] [.border-b]:pb-[var(--ui-section-gap)]`,children:[(0,B.jsxs)(T,{className:`flex items-center gap-2`,children:[(0,B.jsx)(u,{}),`MITM 服务池`]}),(0,B.jsxs)(v,{children:[e.mitmServers.count,` 个动态 HTTPS 服务。`]})]}),(0,B.jsx)(w,{className:`p-0`,children:e.mitmServers.items.length>0?(0,B.jsxs)(P,{children:[(0,B.jsx)(k,{children:(0,B.jsxs)(M,{children:[(0,B.jsx)(A,{children:`Host`}),(0,B.jsx)(A,{children:`端口`}),(0,B.jsx)(A,{children:`Socket`}),(0,B.jsx)(A,{children:`空闲`})]})}),(0,B.jsx)(j,{children:e.mitmServers.items.map(e=>(0,B.jsxs)(M,{children:[(0,B.jsx)(N,{className:`max-w-[260px] truncate font-medium`,title:e.host,children:e.host}),(0,B.jsx)(N,{children:e.port??`-`}),(0,B.jsxs)(N,{children:[e.activeSockets,` / `,e.webSockets,` WS`]}),(0,B.jsx)(N,{className:`text-muted-foreground`,children:e.idleForMs==null?`-`:G(e.idleForMs/1e3)})]},`${e.host}:${e.port??`dynamic`}`))})]}):(0,B.jsx)(m,{className:`border-0 py-10`,children:(0,B.jsxs)(p,{children:[(0,B.jsx)(h,{variant:`icon`,children:(0,B.jsx)(c,{})}),(0,B.jsx)(C,{children:`暂无动态 HTTPS 服务`}),(0,B.jsx)(g,{children:`当前没有活跃的 MITM 目标。`})]})})})]}),(0,B.jsxs)(_,{className:`gap-0 py-0 shadow-none`,children:[(0,B.jsxs)(x,{className:`border-b px-[var(--ui-section-gap)] py-[var(--ui-section-gap)] [.border-b]:pb-[var(--ui-section-gap)]`,children:[(0,B.jsxs)(T,{className:`flex items-center gap-2`,children:[(0,B.jsx)(s,{}),`日志限流`]}),(0,B.jsxs)(v,{children:[`已抑制 `,$?.suppressedTotal??0,` 条重复日志。`]})]}),(0,B.jsx)(w,{className:`p-0`,children:$&&$.keys.length>0?(0,B.jsxs)(P,{children:[(0,B.jsx)(k,{children:(0,B.jsxs)(M,{children:[(0,B.jsx)(A,{children:`Key`}),(0,B.jsx)(A,{children:`级别`}),(0,B.jsx)(A,{children:`输出 / 抑制`}),(0,B.jsx)(A,{children:`最近`})]})}),(0,B.jsx)(j,{children:$.keys.map(e=>(0,B.jsxs)(M,{children:[(0,B.jsx)(N,{className:`max-w-[260px] truncate font-medium`,title:e.key,children:e.key}),(0,B.jsx)(N,{children:(0,B.jsx)(S,{variant:e.level===`error`?`destructive`:e.level===`warn`?`secondary`:`outline`,children:e.level})}),(0,B.jsxs)(N,{children:[e.emitted,` / `,e.suppressed]}),(0,B.jsx)(N,{className:`text-muted-foreground`,children:K(e.lastSeenAt)})]},e.key))})]}):(0,B.jsx)(m,{className:`border-0 py-10`,children:(0,B.jsxs)(p,{children:[(0,B.jsx)(h,{variant:`icon`,children:(0,B.jsx)(s,{})}),(0,B.jsx)(C,{children:`暂无限流记录`}),(0,B.jsx)(g,{children:`当前没有被抑制的重复日志。`})]})})})]})]})]})}export{Z as HealthPanel};