@jonathanleelx/meddle 0.5.0-beta.19 → 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.
- package/dist/core/mock-handler.d.ts +7 -0
- package/dist/core/mock-handler.d.ts.map +1 -1
- package/dist/core/mock-handler.js +136 -7
- package/dist/core/mock-handler.js.map +1 -1
- package/dist/server/mocks.js +3 -3
- package/dist/server/mocks.js.map +1 -1
- package/package.json +1 -1
- package/web/dist/assets/{detail-panel-DyvoHlCG.js → detail-panel-CO_7xRlW.js} +3 -3
- package/web/dist/assets/{global-panel-shell-BJaQ_VLp.js → global-panel-shell-dKKTLNpP.js} +3 -3
- package/web/dist/assets/{health-panel-BnxNCGvw.js → health-panel-CUEWcU8g.js} +1 -1
- package/web/dist/assets/{index-Bu3zaxzE.js → index-B9-_OFNJ.js} +2 -2
- package/web/dist/assets/{mobile-proxy-panel-BxJ8OmLu.js → mobile-proxy-panel-smm4Pg7o.js} +2 -2
- package/web/dist/assets/mock-config-BA0GNr6q.js +1 -0
- package/web/dist/assets/mock-editor-panel-ttVorhGI.js +20 -0
- package/web/dist/assets/{mocks-file-missing-note-B8TTBWtG.js → mocks-file-missing-note-DBYZjOpC.js} +1 -1
- package/web/dist/assets/{monaco-editor-DeJNlo9k.js → monaco-editor-DH2CE6FN.js} +1 -1
- package/web/dist/assets/{pane-split-Db1aWKUO.js → pane-split-40_YQZ0-.js} +1 -1
- package/web/dist/assets/{panel-heading-BAI_lNmT.js → panel-heading-BaLG_KAE.js} +1 -1
- package/web/dist/assets/plugin-code-editor-B2Sc5Ngy.js +2 -0
- package/web/dist/assets/plugin-config-nnVWs8jW.js +2 -0
- package/web/dist/assets/plugin-generator-B2CAEqPa.js +2 -0
- package/web/dist/assets/plugin-test-dialog-BU0As6z0.js +7 -0
- package/web/dist/assets/{route-preview-BZ3vhvsc.js → route-preview-Do3jsXLI.js} +1 -1
- package/web/dist/assets/{rule-ai-assistant-panel-DfivYxZH.js → rule-ai-assistant-panel-g-UkLb_B.js} +2 -2
- package/web/dist/assets/rule-config-Bzw8J0q1.js +15 -0
- package/web/dist/assets/rule-overview-panel-DIBRGnrb.js +1 -0
- package/web/dist/assets/settings-panel-CrvG4M_b.js +1 -0
- package/web/dist/index.html +1 -1
- package/web/dist/assets/mock-config-Dp2D5iiv.js +0 -1
- package/web/dist/assets/mock-editor-panel-zqouxTGb.js +0 -20
- package/web/dist/assets/plugin-code-editor-CQqpaaCR.js +0 -2
- package/web/dist/assets/plugin-config-CjcRhSZm.js +0 -2
- package/web/dist/assets/plugin-generator-Cr_gk3Tp.js +0 -2
- package/web/dist/assets/plugin-test-dialog-B5mVM3XE.js +0 -7
- package/web/dist/assets/rule-config-DSX8bBHe.js +0 -15
- package/web/dist/assets/rule-overview-panel-D5gY3akK.js +0 -1
- package/web/dist/assets/settings-panel-Bfzfsovk.js +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
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{
|
|
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)(
|
|
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
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),[S,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)(b,{className:`h-4 w-4 text-muted-foreground`}),(0,z.jsx)(C,{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)(x,{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)(y,{className:`h-4 w-4 animate-spin`}):(0,z.jsx)(v,{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)(y,{className:`h-4 w-4 shrink-0 animate-spin text-muted-foreground`}):(0,z.jsx)(_,{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:S===e.id,onClick:()=>void $(e.id,!1),children:`取消`}),(0,z.jsxs)(i,{size:`sm`,disabled:S===e.id,onClick:()=>void $(e.id,!0),children:[S===e.id?(0,z.jsx)(y,{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)(C,{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)(y,{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)(x,{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};
|
|
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};
|
|
@@ -1 +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{B as f,Dt as te,G as p,H as m,Nt as h,U as g,W as _,at as v,ct as y,et as b,ft as ne,it as re,lt as x,nt as S,ot as C,rt as w,st as T}from"./index-Bu3zaxzE.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)(b,{variant:e===`critical`?`destructive`:e===`degraded`?`secondary`:`default`,children:[e===`ok`?(0,B.jsx)(h,{}):e===`degraded`?(0,B.jsx)(x,{}):(0,B.jsx)(o,{}),V[e]]})}function oe({icon:e,label:t,value:n,detail:r}){return(0,B.jsxs)(w,{className:`gap-0 py-0 shadow-none`,children:[(0,B.jsx)(T,{className:`border-b px-[var(--ui-section-gap)] py-[var(--ui-section-gap)] [.border-b]:pb-[var(--ui-section-gap)]`,children:(0,B.jsxs)(y,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,B.jsx)(e,{}),t]})}),(0,B.jsxs)(v,{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)(S,{className:`h-7 w-40`}),(0,B.jsx)(S,{className:`h-4 w-64`})]}),(0,B.jsx)(S,{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)(S,{className:`h-32 w-full`},t))}),(0,B.jsx)(S,{className:`h-80 w-full`})]})}function Z(){let[e,t]=(0,z.useState)(null),[r,a]=(0,z.useState)(!0),[o,h]=(0,z.useState)(!1),[S,V]=(0,z.useState)(``),[H,Z]=(0,z.useState)(!0),Q=(0,z.useCallback)(async(e=!1)=>{e?h(!0):a(!0),V(``);try{t(await U())}catch(e){V(e instanceof Error?e.message:`无法读取健康状态`)}finally{a(!1),h(!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:S||`无法读取健康状态`})]}),(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`)}),`刷新`]})]})]}),S&&(0,B.jsxs)(O,{variant:`destructive`,children:[(0,B.jsx)(D,{children:`刷新失败`}),(0,B.jsx)(E,{children:S})]}),(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)(w,{className:`gap-0 py-0 shadow-none`,children:[(0,B.jsxs)(T,{className:`border-b px-[var(--ui-section-gap)] py-[var(--ui-section-gap)] [.border-b]:pb-[var(--ui-section-gap)]`,children:[(0,B.jsxs)(y,{className:`flex items-center gap-2`,children:[(0,B.jsx)(te,{}),`健康检查`]}),(0,B.jsx)(C,{children:`阈值来自当前进程的 MEDDLE_WATCHDOG 配置。`})]}),(0,B.jsx)(v,{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)(w,{className:`gap-0 py-0 shadow-none`,children:[(0,B.jsxs)(T,{className:`border-b px-[var(--ui-section-gap)] py-[var(--ui-section-gap)] [.border-b]:pb-[var(--ui-section-gap)]`,children:[(0,B.jsxs)(y,{className:`flex items-center gap-2`,children:[(0,B.jsx)(ee,{}),`守护策略`]}),(0,B.jsx)(C,{children:`连续命中严重阈值后按策略处理。`}),(0,B.jsx)(re,{children:(0,B.jsx)(b,{variant:e.watchdog.config.enabled?`default`:`secondary`,children:e.watchdog.config.enabled?`已启用`:`已关闭`})})]}),(0,B.jsxs)(v,{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)(x,{}),(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)(w,{className:`gap-0 py-0 shadow-none`,children:[(0,B.jsxs)(T,{className:`border-b px-[var(--ui-section-gap)] py-[var(--ui-section-gap)] [.border-b]:pb-[var(--ui-section-gap)]`,children:[(0,B.jsxs)(y,{className:`flex items-center gap-2`,children:[(0,B.jsx)(u,{}),`MITM 服务池`]}),(0,B.jsxs)(C,{children:[e.mitmServers.count,` 个动态 HTTPS 服务。`]})]}),(0,B.jsx)(v,{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)(f,{className:`border-0 py-10`,children:(0,B.jsxs)(g,{children:[(0,B.jsx)(_,{variant:`icon`,children:(0,B.jsx)(c,{})}),(0,B.jsx)(p,{children:`暂无动态 HTTPS 服务`}),(0,B.jsx)(m,{children:`当前没有活跃的 MITM 目标。`})]})})})]}),(0,B.jsxs)(w,{className:`gap-0 py-0 shadow-none`,children:[(0,B.jsxs)(T,{className:`border-b px-[var(--ui-section-gap)] py-[var(--ui-section-gap)] [.border-b]:pb-[var(--ui-section-gap)]`,children:[(0,B.jsxs)(y,{className:`flex items-center gap-2`,children:[(0,B.jsx)(s,{}),`日志限流`]}),(0,B.jsxs)(C,{children:[`已抑制 `,$?.suppressedTotal??0,` 条重复日志。`]})]}),(0,B.jsx)(v,{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)(b,{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)(f,{className:`border-0 py-10`,children:(0,B.jsxs)(g,{children:[(0,B.jsx)(_,{variant:`icon`,children:(0,B.jsx)(s,{})}),(0,B.jsx)(p,{children:`暂无限流记录`}),(0,B.jsx)(m,{children:`当前没有被抑制的重复日志。`})]})})})]})]})]})}export{Z as HealthPanel};
|
|
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};
|