@jonathanleelx/meddle 0.4.5-beta.6 → 0.5.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/mitm-socket.d.ts +25 -0
- package/dist/core/mitm-socket.d.ts.map +1 -0
- package/dist/core/mitm-socket.js +26 -0
- package/dist/core/mitm-socket.js.map +1 -0
- package/dist/core/remote-access.d.ts +1 -0
- package/dist/core/remote-access.d.ts.map +1 -1
- package/dist/core/remote-access.js +27 -2
- package/dist/core/remote-access.js.map +1 -1
- package/index.js +12 -6
- package/package.json +1 -1
- package/web/dist/assets/{checkbox-BQRlRJrm.js → checkbox-7NvTvLBs.js} +1 -1
- package/web/dist/assets/{code-fixer-Dlsw62Ke.js → code-fixer-DoYxwBWb.js} +1 -1
- package/web/dist/assets/{detail-panel-DElQDCRS.js → detail-panel-vwvLpmzz.js} +1 -1
- package/web/dist/assets/{global-panel-shell-CNR5hbEs.js → global-panel-shell-Dq8vMdMI.js} +1 -1
- package/web/dist/assets/{health-panel-BKOR7Y8q.js → health-panel-CVQcuI1d.js} +1 -1
- package/web/dist/assets/{index-otwkxfTB.js → index-DJ5BnqEk.js} +2 -2
- package/web/dist/assets/index-PcoCj3ST.css +2 -0
- package/web/dist/assets/mobile-proxy-panel-DMJRIDMK.js +8 -0
- package/web/dist/assets/{mock-config-COLWxz2R.js → mock-config-BTdHrudB.js} +1 -1
- package/web/dist/assets/{mock-editor-panel-Bbkaq85N.js → mock-editor-panel-ztb1w__0.js} +1 -1
- package/web/dist/assets/{monaco-editor-DYWjOxN7.js → monaco-editor-CHNSCVe0.js} +1 -1
- package/web/dist/assets/{plugin-code-editor-hGuv6MC3.js → plugin-code-editor-C_h_-lKr.js} +1 -1
- package/web/dist/assets/{plugin-config-DkZcWYNN.js → plugin-config-B5tDGCq-.js} +1 -1
- package/web/dist/assets/{plugin-generator-B217-RVa.js → plugin-generator-CojssHdE.js} +1 -1
- package/web/dist/assets/{plugin-test-dialog-oWz-o_XG.js → plugin-test-dialog-iWeHVCGW.js} +1 -1
- package/web/dist/assets/{route-preview-Dv6AYYUb.js → route-preview-BecifYSe.js} +1 -1
- package/web/dist/assets/{rule-ai-assistant-panel-DsJ1sdXd.js → rule-ai-assistant-panel-LWDaNQKt.js} +1 -1
- package/web/dist/assets/rule-config-CLte-qNZ.js +15 -0
- package/web/dist/assets/{select-DSwkV3cG.js → select-C5thwxXQ.js} +1 -1
- package/web/dist/assets/{settings-panel-DSSxRrV9.js → settings-panel-Bx_qz1RQ.js} +1 -1
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-DQtOwhpd.css +0 -2
- package/web/dist/assets/mobile-proxy-panel-m88i11PB.js +0 -8
- package/web/dist/assets/rule-config-DuUVPgbM.js +0 -15
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as e,f as t,t as n,u as r}from"./button-BTToMaBW.js";import"./dist-C6eaYCUo.js";import{t as i}from"./circle-x-C9USji_R.js";import{t as a}from"./code-5_eJ_XpJ.js";import{t as o}from"./copy-BYjq1hdN.js";import{t as s}from"./wand-sparkles-wkul5vje.js";import"./es2015-CfXu88Y7.js";import{o as ee,r as te}from"./ai-config-store-DQXVJVn_.js";import{$ as ne,A as c,X as l,_ as re,b as u,d as ie,f as ae,g as oe,h as se,m as d,mt as ce,ot as f,p as le,pt as ue,u as p,v as de,y as fe,z as m}from"./index-
|
|
1
|
+
import{a as e,f as t,t as n,u as r}from"./button-BTToMaBW.js";import"./dist-C6eaYCUo.js";import{t as i}from"./circle-x-C9USji_R.js";import{t as a}from"./code-5_eJ_XpJ.js";import{t as o}from"./copy-BYjq1hdN.js";import{t as s}from"./wand-sparkles-wkul5vje.js";import"./es2015-CfXu88Y7.js";import{o as ee,r as te}from"./ai-config-store-DQXVJVn_.js";import{$ as ne,A as c,X as l,_ as re,b as u,d as ie,f as ae,g as oe,h as se,m as d,mt as ce,ot as f,p as le,pt as ue,u as p,v as de,y as fe,z as m}from"./index-DJ5BnqEk.js";import{t as pe}from"./textarea-vuxJwU0x.js";var h=t(r(),1),g=e();function _({open:e=!1,onOpenChange:t,embedded:r=!1,onPluginSaved:_}){let[v,y]=(0,h.useState)(``),[b,x]=(0,h.useState)(``),[S,C]=(0,h.useState)(``),[w,T]=(0,h.useState)(``),[E,D]=(0,h.useState)(!1),[O,k]=(0,h.useState)(!1),[A,j]=(0,h.useState)(``),[M,N]=(0,h.useState)(``),[P,F]=(0,h.useState)(null),[I,L]=(0,h.useState)(null),[R,z]=(0,h.useState)(``),[me,B]=(0,h.useState)(!1),[V,H]=(0,h.useState)(0),[U,W]=(0,h.useState)(0),[G,K]=(0,h.useState)(!1),[q,J]=(0,h.useState)(!1),Y=te(),X=ee(Y),he=async()=>{if(!v.trim()||!b.trim()){L(`error`),z(`请填写插件名称和描述`);return}if(!X){L(`error`),z(`AI 配置未完成,请先配置 AI 服务`);return}D(!0),L(null),z(`正在连接 AI 服务...`),j(``),H(0),W(0);let e=Date.now(),t=0;try{let n={name:v,description:b,hooks:S.split(`,`).map(e=>e.trim()).filter(Boolean),permissions:w.split(`,`).map(e=>e.trim()).filter(Boolean)},r=await fetch(`/api/plugins/generate-stream`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({requirement:n,aiConfig:{provider:Y.provider,apiKey:Y.apiKey,baseUrl:Y.baseUrl,model:Y.model}})});if(!r.ok)throw Error(`请求失败: ${r.status}`);let i=r.body?.getReader(),a=new TextDecoder;if(!i)throw Error(`无法读取响应流`);let o=``;for(;;){let{done:n,value:r}=await i.read();if(n)break;o+=a.decode(r,{stream:!0});let s=o.split(`
|
|
2
2
|
`);o=s.pop()||``;for(let n of s)if(!n.startsWith(`event:`)&&n.startsWith(`data:`)){let r=n.slice(5).trim();try{let n=JSON.parse(r);if(n.status===`generating`)z(`AI 正在生成代码...`),W(10);else if(n.chunk){t++;let r=n.accumulated||n.chunk;j(r),H(r.length),W(Math.min(90,10+t*2));let i=((Date.now()-e)/1e3).toFixed(1);z(`生成中... (${r.length} 字符, ${i}s)`)}else if(n.status===`success`){j(n.plugin.code),N(n.plugin.filename),F(n.plugin.manifest),H(n.plugin.code.length),W(100),L(`success`);let t=((Date.now()-e)/1e3).toFixed(1);z(`插件代码生成成功!(${n.plugin.code.length} 字符, ${t}s)`)}else if(n.error)throw Error(n.error)}catch(e){if(e instanceof Error&&e.message!==`Unexpected end of JSON input`)throw e}}}}catch(e){L(`error`),z(e instanceof Error?e.message:`生成失败`),W(0)}finally{D(!1)}},Z=async()=>{if(!A||!M){L(`error`),z(`没有可保存的插件代码`);return}k(!0),L(null),z(`正在保存插件...`);try{let e=await fetch(`/api/plugins/save`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({filename:M,code:A})});if(!e.ok){let t=await e.json();throw Error(t.error||`保存失败`)}await e.json(),L(`success`),z(`插件已保存!现在可以热加载并测试。`),K(!0),window.dispatchEvent(new CustomEvent(`plugins-custom-updated`)),p.success(`插件保存成功`),_&&_(),window.dispatchEvent(new CustomEvent(`plugins-custom-updated`))}catch(e){let t=e instanceof Error?e.message:`保存失败`;L(`error`),z(t),p.error(t)}finally{k(!1)}};ie({active:(e||r)&&!!A&&!G,enabled:!O&&!E&&!!M,priority:ae.panel,onSave:Z});let ge=async()=>{A&&(await navigator.clipboard.writeText(A),B(!0),setTimeout(()=>B(!1),2e3))},_e=async()=>{J(!0);try{let e=await fetch(`/api/plugins/reload`,{method:`POST`});if(!e.ok){let t=await e.json();throw Error(t.error||`热加载失败`)}let n=await e.json();L(`success`),z(`成功热加载 ${n.count} 个插件!插件已激活,可以使用了。`),_&&_(),setTimeout(()=>{t?.(!1),Q()},3e3)}catch(e){L(`error`),z(e instanceof Error?e.message:`热加载失败`)}finally{J(!1)}},Q=()=>{y(``),x(``),C(``),T(``),j(``),N(``),F(null),L(null),z(``),B(!1),H(0),W(0),K(!1),J(!1)},$=(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(de,{className:`px-6 pt-6 pb-4`,children:[(0,g.jsxs)(fe,{className:`flex items-center gap-2`,children:[(0,g.jsx)(l,{className:`h-5 w-5`}),`AI 插件生成器`]}),(0,g.jsx)(re,{children:`使用 AI 根据插件系统设计和您的需求自动生成自定义插件代码`})]}),(0,g.jsx)(d,{}),(0,g.jsxs)(`div`,{className:`app-panel-content`,children:[!X&&(0,g.jsx)(`div`,{className:`bg-yellow-50 dark:bg-yellow-950/20 border border-yellow-200 dark:border-yellow-900 rounded-md p-3`,children:(0,g.jsx)(`p`,{className:`text-sm text-yellow-700 dark:text-yellow-300`,children:`AI 功能未配置或未启用,请先在设置中配置 AI 服务`})}),(0,g.jsxs)(`div`,{className:`app-section`,children:[(0,g.jsxs)(`div`,{className:`app-field-group`,children:[(0,g.jsxs)(u,{htmlFor:`pluginName`,children:[`插件名称 `,(0,g.jsx)(`span`,{className:`text-red-500`,children:`*`})]}),(0,g.jsx)(c,{id:`pluginName`,value:v,onChange:e=>y(e.target.value),placeholder:`例如:请求日志分析器`,disabled:E||O})]}),(0,g.jsxs)(`div`,{className:`app-field-group`,children:[(0,g.jsxs)(u,{htmlFor:`pluginDescription`,children:[`插件描述 `,(0,g.jsx)(`span`,{className:`text-red-500`,children:`*`})]}),(0,g.jsx)(pe,{id:`pluginDescription`,value:b,onChange:e=>x(e.target.value),placeholder:`详细描述插件的功能,例如:分析HTTP请求日志,统计各个API的调用次数、响应时间等信息,并在控制台输出统计报告`,rows:4,disabled:E||O})]}),(0,g.jsxs)(`div`,{className:`app-field-group`,children:[(0,g.jsx)(u,{htmlFor:`hooks`,children:`需要的 Hooks(可选,用逗号分隔)`}),(0,g.jsx)(c,{id:`hooks`,value:S,onChange:e=>C(e.target.value),placeholder:`例如:onRequestStart, onAfterResponse`,disabled:E||O}),(0,g.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`可选:onRequestStart, onBeforeProxy, onBeforeResponse, onAfterResponse, onError`})]}),(0,g.jsxs)(`div`,{className:`app-field-group`,children:[(0,g.jsx)(u,{htmlFor:`permissions`,children:`需要的权限(可选,用逗号分隔)`}),(0,g.jsx)(c,{id:`permissions`,value:w,onChange:e=>T(e.target.value),placeholder:`例如:proxy:read, storage:write`,disabled:E||O}),(0,g.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`可选:proxy:read, proxy:write, response:shortcircuit, storage:read, storage:write`})]})]}),E&&U>0&&(0,g.jsxs)(`div`,{className:`app-field-group`,children:[(0,g.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,g.jsx)(`span`,{className:`text-muted-foreground`,children:`生成进度`}),(0,g.jsxs)(`span`,{className:`font-medium`,children:[U,`%`]})]}),(0,g.jsx)(`div`,{className:`w-full bg-muted rounded-full h-2 overflow-hidden`,children:(0,g.jsx)(`div`,{className:`bg-primary h-full transition-all duration-300 ease-out`,style:{width:`${U}%`}})})]}),(A||E)&&(0,g.jsxs)(`div`,{className:`app-field-group`,children:[(0,g.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,g.jsxs)(u,{className:`flex items-center gap-2`,children:[(0,g.jsx)(a,{className:`h-4 w-4`}),E?`正在生成插件代码`:`生成的插件代码`]}),(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[V>0&&(0,g.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[V,` 字符`]}),!E&&A&&(0,g.jsx)(n,{variant:`ghost`,size:`sm`,onClick:ge,className:`h-8`,children:me?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(ce,{className:`h-4 w-4 mr-1`}),`已复制`]}):(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(o,{className:`h-4 w-4 mr-1`}),`复制`]})})]})]}),(0,g.jsxs)(`div`,{className:`bg-muted rounded-md p-4 max-h-[400px] overflow-auto relative`,children:[E&&(0,g.jsx)(`div`,{className:`absolute top-2 right-2`,children:(0,g.jsx)(f,{className:`h-4 w-4 animate-spin text-muted-foreground`})}),(0,g.jsx)(`pre`,{className:`text-xs font-mono whitespace-pre-wrap break-all`,children:A||`等待 AI 响应...`})]}),P&&(0,g.jsxs)(`div`,{className:`bg-blue-50 dark:bg-blue-950/20 border border-blue-200 dark:border-blue-900 rounded-md p-3 space-y-2`,children:[(0,g.jsx)(`p`,{className:`text-sm font-medium text-blue-900 dark:text-blue-100`,children:`插件信息`}),(0,g.jsxs)(`div`,{className:`text-xs space-y-1 text-blue-700 dark:text-blue-300`,children:[(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`strong`,{children:`ID:`}),` `,P.id]}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`strong`,{children:`名称:`}),` `,P.name]}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`strong`,{children:`版本:`}),` `,P.version]}),(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,g.jsx)(`strong`,{children:`Hooks:`}),(0,g.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:P.hooks.map(e=>(0,g.jsx)(m,{variant:`secondary`,className:`text-xs`,children:e},e))})]}),(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,g.jsx)(`strong`,{children:`权限:`}),(0,g.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:P.permissions.map(e=>(0,g.jsx)(m,{variant:`outline`,className:`text-xs`,children:e},e))})]})]})]})]}),R&&(0,g.jsxs)(`div`,{className:`flex items-start gap-2 p-3 rounded-md border ${I===`success`?`bg-green-50 dark:bg-green-950/20 border-green-200 dark:border-green-900`:I===`error`?`bg-red-50 dark:bg-red-950/20 border-red-200 dark:border-red-900`:`bg-blue-50 dark:bg-blue-950/20 border-blue-200 dark:border-blue-900`}`,children:[I===`success`&&(0,g.jsx)(ue,{className:`h-4 w-4 text-green-600 dark:text-green-400 mt-0.5`}),I===`error`&&(0,g.jsx)(i,{className:`h-4 w-4 text-red-600 dark:text-red-400 mt-0.5`}),E&&(0,g.jsx)(f,{className:`h-4 w-4 text-blue-600 dark:text-blue-400 mt-0.5 animate-spin`}),(0,g.jsx)(`span`,{className:`text-xs flex-1 ${I===`success`?`text-green-700 dark:text-green-300`:I===`error`?`text-red-700 dark:text-red-300`:`text-blue-700 dark:text-blue-300`}`,children:R})]})]}),(0,g.jsx)(d,{}),(0,g.jsxs)(`div`,{className:`px-6 py-4 flex justify-between gap-2`,children:[(0,g.jsx)(n,{variant:`outline`,size:`sm`,onClick:()=>{t?.(!1),Q()},disabled:E||O||q,children:G?`完成`:`取消`}),(0,g.jsx)(`div`,{className:`flex gap-2`,children:A?G?(0,g.jsx)(n,{size:`sm`,onClick:_e,disabled:q,className:`bg-green-600 hover:bg-green-700`,children:q?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(f,{className:`h-4 w-4 mr-1 animate-spin`}),`加载中...`]}):(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(l,{className:`h-4 w-4 mr-1`}),`热加载并测试`]})}):(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(n,{variant:`outline`,size:`sm`,onClick:()=>{j(``),N(``),F(null),L(null),z(``)},disabled:E||O,children:`重新生成`}),(0,g.jsx)(le,{size:`sm`,onClick:Z,disabled:O,children:O?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(f,{"data-icon":`inline-start`,className:`animate-spin`}),`保存中...`]}):(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(ne,{"data-icon":`inline-start`}),`保存插件`]})})]}):(0,g.jsx)(n,{size:`sm`,onClick:he,disabled:!X||E||O||!v.trim()||!b.trim(),children:E?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(f,{className:`h-4 w-4 mr-1 animate-spin`}),`生成中...`]}):(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(s,{className:`h-4 w-4 mr-1`}),`生成插件`]})})})]})]});return r?(0,g.jsx)(`div`,{className:`flex h-full min-h-0 flex-col`,children:$}):(0,g.jsx)(se,{open:e,onOpenChange:e=>{t?.(e),e||Q()},children:(0,g.jsx)(oe,{className:`p-0 flex flex-col`,resizable:!0,defaultWidth:900,storageKey:`plugin-generator`,children:$})})}export{_ as PluginGenerator};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as e,f as t,l as n,t as r,u as i}from"./button-BTToMaBW.js";import"./dist-C6eaYCUo.js";import{t as a}from"./arrow-right-B4Mrlj2-.js";import{t as o}from"./circle-alert-Q8cZk9Rv.js";import{t as s}from"./circle-x-C9USji_R.js";import{t as ee}from"./pencil-line-Cqe41E4h.js";import{t as c}from"./refresh-cw-CG3HaiQT.js";import{t as te}from"./wand-sparkles-wkul5vje.js";import"./es2015-CfXu88Y7.js";import{i as ne,o as re,r as ie}from"./ai-config-store-DQXVJVn_.js";import{A as ae,B as l,H as u,U as d,_ as oe,b as f,ft as se,g as ce,h as le,lt as ue,m as p,ot as m,pt as de,q as h,st as fe,v as pe,y as me,z as g}from"./index-otwkxfTB.js";import{t as _}from"./body-diff-view-D7dCWajG.js";import{n as he,t as ge}from"./monaco-editor-DYWjOxN7.js";import{t as _e}from"./textarea-vuxJwU0x.js";var ve=n(`circle-play`,[[`path`,{d:`M9 9.003a1 1 0 0 1 1.517-.859l4.997 2.997a1 1 0 0 1 0 1.718l-4.997 2.997A1 1 0 0 1 9 14.996z`,key:`kmsa83`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),v=t(i(),1),y=e();function b(e){let t=new Map;return!e||typeof e!=`object`||Object.entries(e).forEach(([e,n])=>{t.set(e.toLowerCase(),{displayKey:e,value:n==null?``:String(n)})}),t}function x(e,t){let n=b(e),r=b(t);return Array.from(new Set([...n.keys(),...r.keys()])).sort().map(e=>{let t=n.get(e),i=r.get(e),a=t?.value??``,o=i?.value??``,s=`unchanged`;return!t&&i?s=`added`:t&&!i?s=`removed`:a!==o&&(s=`changed`),{key:e,displayKey:i?.displayKey??t?.displayKey??e,originalValue:a,modifiedValue:o,status:s}})}function S(e,t){let n=`rounded-md border px-2 py-1.5`;return e===`unchanged`?`${n} border-transparent`:e===`changed`?`${n} border-orange-300 bg-orange-500/10`:e===`added`?t===`modified`?`${n} border-green-300 bg-green-500/10`:`${n} border-transparent opacity-50`:e===`removed`?t===`original`?`${n} border-red-300 bg-red-500/10`:`${n} border-transparent opacity-50`:n}function ye({original:e,modified:t,mode:n=`split`}){let r=x(e,t);return n===`inline`?(0,y.jsx)(`div`,{className:`bg-muted/50 rounded-md p-2 text-xs font-mono max-h-[220px] overflow-auto space-y-1`,children:r.map(e=>(0,y.jsxs)(`div`,{className:`rounded-md border px-2 py-1.5 ${e.status===`unchanged`?`border-transparent`:e.status===`changed`?`border-orange-300 bg-orange-500/10`:e.status===`added`?`border-green-300 bg-green-500/10`:`border-red-300 bg-red-500/10`}`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,y.jsx)(`span`,{className:`text-muted-foreground`,children:e.displayKey}),(0,y.jsx)(g,{variant:`outline`,className:`h-5 px-1.5 text-[10px] font-normal`,children:e.status===`unchanged`?`未变`:e.status===`changed`?`修改`:e.status===`added`?`新增`:`删除`})]}),e.status===`changed`&&(0,y.jsxs)(`div`,{className:`mt-1 space-y-1`,children:[(0,y.jsxs)(`div`,{className:`text-red-700 dark:text-red-300`,children:[(0,y.jsx)(`span`,{className:`mr-1`,children:`-`}),e.originalValue||(0,y.jsx)(`span`,{className:`text-muted-foreground italic`,children:`(无)`})]}),(0,y.jsxs)(`div`,{className:`text-green-700 dark:text-green-300`,children:[(0,y.jsx)(`span`,{className:`mr-1`,children:`+`}),e.modifiedValue||(0,y.jsx)(`span`,{className:`text-muted-foreground italic`,children:`(无)`})]})]}),e.status===`added`&&(0,y.jsxs)(`div`,{className:`mt-1 text-green-700 dark:text-green-300`,children:[(0,y.jsx)(`span`,{className:`mr-1`,children:`+`}),e.modifiedValue||(0,y.jsx)(`span`,{className:`text-muted-foreground italic`,children:`(无)`})]}),e.status===`removed`&&(0,y.jsxs)(`div`,{className:`mt-1 text-red-700 dark:text-red-300`,children:[(0,y.jsx)(`span`,{className:`mr-1`,children:`-`}),e.originalValue||(0,y.jsx)(`span`,{className:`text-muted-foreground italic`,children:`(无)`})]}),e.status===`unchanged`&&(0,y.jsx)(`div`,{className:`mt-1`,children:e.modifiedValue||e.originalValue||(0,y.jsx)(`span`,{className:`text-muted-foreground italic`,children:`(无)`})})]},e.key))}):(0,y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:`原始`}),(0,y.jsx)(`div`,{className:`bg-muted/50 rounded-md p-2 text-xs font-mono max-h-[220px] overflow-auto space-y-1`,children:r.map(e=>(0,y.jsxs)(`div`,{className:S(e.status,`original`),children:[(0,y.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.displayKey,`:`]}),` `,e.originalValue||(0,y.jsx)(`span`,{className:`text-muted-foreground italic`,children:`(无)`})]},`original-${e.key}`))})]}),(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:`修改后`}),(0,y.jsx)(`div`,{className:`bg-muted/50 rounded-md p-2 text-xs font-mono max-h-[220px] overflow-auto space-y-1`,children:r.map(e=>(0,y.jsxs)(`div`,{className:S(e.status,`modified`),children:[(0,y.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.displayKey,`:`]}),` `,e.modifiedValue||(0,y.jsx)(`span`,{className:`text-muted-foreground italic`,children:`(无)`})]},`modified-${e.key}`))})]})]})}function be(e){switch(e){case`generating`:return`AI 正在流式生成修复代码`;case`saving`:return`正在保存修复后的插件代码`;case`reloading`:return`正在热加载插件`;case`retesting`:return`正在重新执行插件测试`;default:return``}}function C({open:e=!1,onOpenChange:t,embedded:n=!1,pluginId:i,pluginName:b,hooks:x,onPluginFixed:S}){let[C,xe]=(0,v.useState)(!1),[w,T]=(0,v.useState)(!1),[Se,Ce]=(0,v.useState)(`https://365.wps.cn/home`),[we,Te]=(0,v.useState)(`GET`),[E,D]=(0,v.useState)(`standalone`),[O,k]=(0,v.useState)(null),[A,Ee]=(0,v.useState)(`split`),[j,De]=(0,v.useState)(`inline`),[M,N]=(0,v.useState)(null),[P,F]=(0,v.useState)(``),[I,L]=(0,v.useState)(``),[R,Oe]=(0,v.useState)(!1),[z,B]=(0,v.useState)(null),[V,H]=(0,v.useState)(``),[ke,U]=(0,v.useState)(`normal`),[W,Ae]=(0,v.useState)(``),[G,K]=(0,v.useState)(`idle`),q=ie(),J=ne(q),je=J?{provider:J.provider,apiKey:J.apiKey,baseUrl:J.baseUrl,model:J.model}:{provider:q.provider,apiKey:q.apiKey,baseUrl:q.baseUrl,model:q.model},Y=re(q),X=i.startsWith(`local.`)?`${i.slice(6)}.js`:``,Z=(0,v.useCallback)(async()=>{if(!X||!e){F(``),L(``),B(null);return}Oe(!0),B(null);try{let e=await fetch(`/api/plugins/custom/${encodeURIComponent(X)}/code`);if(!e.ok){let t=await e.json();throw Error(t.error||`读取插件源码失败`)}let t=await e.json();F(t.code||``),!w&&!V&&L(t.code||``)}catch(e){F(``),L(``),B(e instanceof Error?e.message:`读取插件源码失败`)}finally{Oe(!1)}},[X,w,V,e]);(0,v.useEffect)(()=>{Z()},[Z]);let Q=(0,v.useMemo)(()=>{let e=[];return O?.error&&e.push({hookName:`test`,message:O.error}),Object.entries(O?.hookResults||{}).forEach(([t,n])=>{n?.status===`error`&&e.push({hookName:t,message:n.error||`未知错误`,stack:n.stack})}),O?.realRequest?.fetchError&&e.push({hookName:`fetch`,message:O.realRequest.fetchError}),e},[O]),Me=Q.length>0&&!!X,Ne=!!I&&!!(V||G===`idle`&&I&&P&&I!==P),Pe=async(e,t,n)=>{K(`saving`);let r=await fetch(`/api/plugins/custom/${encodeURIComponent(X)}/code`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({code:e})});if(!r.ok){let e=await r.json();throw Error(e.error||`保存修复后的代码失败`)}K(`reloading`);let i=await fetch(`/api/plugins/reload`,{method:`POST`});if(!i.ok){let e=await i.json().catch(()=>({error:`热加载失败`}));throw Error(e.error||`热加载失败`)}F(e),H(e),U(`diff`),window.dispatchEvent(new CustomEvent(`plugins-custom-updated`)),S?.(),n&&(K(`retesting`),await Fe()),N({status:`success`,message:t}),K(`idle`)},Fe=async()=>{xe(!0),k(null),N(null);try{let e=await fetch(`/api/plugins/test`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pluginId:i,url:Se,method:we,integrated:E===`integrated`})});if(!e.ok){let t=await e.json();throw Error(t.error||`测试失败`)}k((await e.json()).results)}catch(e){k({error:e instanceof Error?e.message:`测试失败`})}finally{xe(!1)}},$=(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)(pe,{className:`px-6 pt-6 pb-4`,children:[(0,y.jsxs)(me,{className:`flex items-center gap-2`,children:[(0,y.jsx)(h,{className:`h-5 w-5`}),`测试插件: `,b]}),(0,y.jsx)(oe,{children:`发起真实 HTTP 请求,在请求/响应过程中运行插件代码`})]}),(0,y.jsx)(p,{}),(0,y.jsxs)(`div`,{className:`app-panel-content`,children:[(0,y.jsxs)(`div`,{className:`app-section`,children:[(0,y.jsxs)(`div`,{className:`app-field-group`,children:[(0,y.jsx)(f,{htmlFor:`testUrl`,children:`请求 URL`}),(0,y.jsx)(ae,{id:`testUrl`,value:Se,onChange:e=>Ce(e.target.value),placeholder:`https://example.com/page`,disabled:C})]}),(0,y.jsxs)(`div`,{className:`app-field-group`,children:[(0,y.jsx)(f,{children:`HTTP 方法`}),(0,y.jsx)(`div`,{className:`flex gap-2`,children:[`GET`,`POST`,`PUT`,`DELETE`].map(e=>(0,y.jsx)(r,{type:`button`,variant:we===e?`selected`:`outline`,size:`sm`,onClick:()=>Te(e),disabled:C,children:e},e))})]}),(0,y.jsxs)(`div`,{className:`app-field-group`,children:[(0,y.jsx)(f,{children:`测试模式`}),(0,y.jsxs)(`div`,{className:`flex gap-2 flex-wrap`,children:[(0,y.jsx)(r,{type:`button`,variant:E===`standalone`?`selected`:`outline`,size:`sm`,onClick:()=>D(`standalone`),disabled:C,title:`直接请求 URL,不走路由与 Mock,便于排查插件自身逻辑`,children:`单独测试`}),(0,y.jsx)(r,{type:`button`,variant:E===`integrated`?`selected`:`outline`,size:`sm`,onClick:()=>D(`integrated`),disabled:C,title:`与真实代理一致:先路由解析、Mock 匹配,再请求,便于排查整体链路`,children:`集成测试`})]}),(0,y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:E===`standalone`?`直接请求上述 URL,不经过路由规则和 Mock,适合验证插件逻辑。`:`先按路由规则解析目标、匹配 Mock,再请求,与经代理的真实请求一致,适合排查链路问题。`})]}),(0,y.jsx)(`div`,{className:`bg-blue-50 dark:bg-blue-950/20 border border-blue-200 dark:border-blue-900 rounded-md p-3`,children:(0,y.jsxs)(`p`,{className:`text-xs text-blue-700 dark:text-blue-300`,children:[(0,y.jsx)(`strong`,{children:`测试流程:`}),` 发起真实请求 → 获取服务器响应 → 运行插件 Hook(`,x.join(`, `),`)→ 展示对比结果`]})})]}),!!X&&(0,y.jsxs)(`div`,{className:`space-y-3`,children:[(0,y.jsx)(p,{}),(0,y.jsxs)(`div`,{className:`space-y-2`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,y.jsxs)(`h3`,{className:`text-sm font-medium flex items-center gap-2`,children:[(0,y.jsx)(se,{className:`h-4 w-4`}),`插件代码`]}),(0,y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,y.jsx)(l,{value:ke,onValueChange:e=>U(e),children:(0,y.jsxs)(u,{className:`h-7`,children:[(0,y.jsx)(d,{value:`normal`,className:`px-2 text-xs`,children:`正常视图`}),(0,y.jsx)(d,{value:`diff`,className:`px-2 text-xs`,disabled:!Ne,children:`Diff 视图`})]})}),(0,y.jsx)(g,{variant:`outline`,className:`text-xs font-normal`,children:X}),(0,y.jsx)(r,{size:`sm`,variant:`ghost`,onClick:Z,disabled:R||w,children:R?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(m,{className:`h-4 w-4 mr-1 animate-spin`}),`读取中`]}):(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(c,{className:`h-4 w-4 mr-1`}),`刷新代码`]})})]})]}),z?(0,y.jsx)(`div`,{className:`rounded-md border border-red-200 bg-red-50/80 p-3 text-sm text-red-700 dark:border-red-900 dark:bg-red-950/20 dark:text-red-300`,children:z}):ke===`diff`&&Ne?(0,y.jsxs)(`div`,{className:`space-y-2`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`左侧是原代码,右侧是 AI 修复后的代码`}),G!==`idle`&&(0,y.jsx)(g,{variant:`outline`,className:`text-xs font-normal`,children:be(G)})]}),(0,y.jsx)(ge,{original:I||P,modified:V||P,language:`javascript`,minHeight:`320px`})]}):(0,y.jsx)(he,{value:w&&V?V:P,onChange:()=>{},language:`javascript`,readOnly:!0,minHeight:`260px`}),(0,y.jsxs)(`div`,{className:`space-y-2 pt-2`,children:[(0,y.jsx)(f,{htmlFor:`plugin-extra-instruction`,children:`额外信息`}),(0,y.jsx)(_e,{id:`plugin-extra-instruction`,value:W,onChange:e=>Ae(e.target.value),placeholder:`例如:补充 onBeforeResponse 里对 JSON 响应的判空逻辑;保留现有 hooks 和 manifest,不要改插件 id。`,className:`min-h-[88px]`,disabled:w||R}),(0,y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`输入额外要求后,AI 会基于当前插件代码直接更新并热加载。`}),(0,y.jsx)(r,{size:`sm`,variant:`outline`,onClick:async()=>{if(!(!X||!W.trim()||!Y||w)){T(!0),N(null),H(``),L(P);try{K(`generating`);let e=await fetch(`/api/plugins/revise-stream`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({originalCode:P,instruction:W.trim(),requirement:{name:b,description:`根据额外要求更新插件 ${b},并保持 hooks 行为正确。Hooks: ${x.join(`, `)}`,hooks:x},aiConfig:je})});if(!e.ok){let t=await e.json();throw Error(t.error||`AI 更新代码失败`)}let t=e.body?.getReader(),n=new TextDecoder;if(!t)throw Error(`无法读取 AI 更新流`);let r=``,i=``;for(;;){let{done:e,value:a}=await t.read();if(e)break;i+=n.decode(a,{stream:!0});let o=i.split(`
|
|
1
|
+
import{a as e,f as t,l as n,t as r,u as i}from"./button-BTToMaBW.js";import"./dist-C6eaYCUo.js";import{t as a}from"./arrow-right-B4Mrlj2-.js";import{t as o}from"./circle-alert-Q8cZk9Rv.js";import{t as s}from"./circle-x-C9USji_R.js";import{t as ee}from"./pencil-line-Cqe41E4h.js";import{t as c}from"./refresh-cw-CG3HaiQT.js";import{t as te}from"./wand-sparkles-wkul5vje.js";import"./es2015-CfXu88Y7.js";import{i as ne,o as re,r as ie}from"./ai-config-store-DQXVJVn_.js";import{A as ae,B as l,H as u,U as d,_ as oe,b as f,ft as se,g as ce,h as le,lt as ue,m as p,ot as m,pt as de,q as h,st as fe,v as pe,y as me,z as g}from"./index-DJ5BnqEk.js";import{t as _}from"./body-diff-view-D7dCWajG.js";import{n as he,t as ge}from"./monaco-editor-CHNSCVe0.js";import{t as _e}from"./textarea-vuxJwU0x.js";var ve=n(`circle-play`,[[`path`,{d:`M9 9.003a1 1 0 0 1 1.517-.859l4.997 2.997a1 1 0 0 1 0 1.718l-4.997 2.997A1 1 0 0 1 9 14.996z`,key:`kmsa83`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),v=t(i(),1),y=e();function b(e){let t=new Map;return!e||typeof e!=`object`||Object.entries(e).forEach(([e,n])=>{t.set(e.toLowerCase(),{displayKey:e,value:n==null?``:String(n)})}),t}function x(e,t){let n=b(e),r=b(t);return Array.from(new Set([...n.keys(),...r.keys()])).sort().map(e=>{let t=n.get(e),i=r.get(e),a=t?.value??``,o=i?.value??``,s=`unchanged`;return!t&&i?s=`added`:t&&!i?s=`removed`:a!==o&&(s=`changed`),{key:e,displayKey:i?.displayKey??t?.displayKey??e,originalValue:a,modifiedValue:o,status:s}})}function S(e,t){let n=`rounded-md border px-2 py-1.5`;return e===`unchanged`?`${n} border-transparent`:e===`changed`?`${n} border-orange-300 bg-orange-500/10`:e===`added`?t===`modified`?`${n} border-green-300 bg-green-500/10`:`${n} border-transparent opacity-50`:e===`removed`?t===`original`?`${n} border-red-300 bg-red-500/10`:`${n} border-transparent opacity-50`:n}function ye({original:e,modified:t,mode:n=`split`}){let r=x(e,t);return n===`inline`?(0,y.jsx)(`div`,{className:`bg-muted/50 rounded-md p-2 text-xs font-mono max-h-[220px] overflow-auto space-y-1`,children:r.map(e=>(0,y.jsxs)(`div`,{className:`rounded-md border px-2 py-1.5 ${e.status===`unchanged`?`border-transparent`:e.status===`changed`?`border-orange-300 bg-orange-500/10`:e.status===`added`?`border-green-300 bg-green-500/10`:`border-red-300 bg-red-500/10`}`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,y.jsx)(`span`,{className:`text-muted-foreground`,children:e.displayKey}),(0,y.jsx)(g,{variant:`outline`,className:`h-5 px-1.5 text-[10px] font-normal`,children:e.status===`unchanged`?`未变`:e.status===`changed`?`修改`:e.status===`added`?`新增`:`删除`})]}),e.status===`changed`&&(0,y.jsxs)(`div`,{className:`mt-1 space-y-1`,children:[(0,y.jsxs)(`div`,{className:`text-red-700 dark:text-red-300`,children:[(0,y.jsx)(`span`,{className:`mr-1`,children:`-`}),e.originalValue||(0,y.jsx)(`span`,{className:`text-muted-foreground italic`,children:`(无)`})]}),(0,y.jsxs)(`div`,{className:`text-green-700 dark:text-green-300`,children:[(0,y.jsx)(`span`,{className:`mr-1`,children:`+`}),e.modifiedValue||(0,y.jsx)(`span`,{className:`text-muted-foreground italic`,children:`(无)`})]})]}),e.status===`added`&&(0,y.jsxs)(`div`,{className:`mt-1 text-green-700 dark:text-green-300`,children:[(0,y.jsx)(`span`,{className:`mr-1`,children:`+`}),e.modifiedValue||(0,y.jsx)(`span`,{className:`text-muted-foreground italic`,children:`(无)`})]}),e.status===`removed`&&(0,y.jsxs)(`div`,{className:`mt-1 text-red-700 dark:text-red-300`,children:[(0,y.jsx)(`span`,{className:`mr-1`,children:`-`}),e.originalValue||(0,y.jsx)(`span`,{className:`text-muted-foreground italic`,children:`(无)`})]}),e.status===`unchanged`&&(0,y.jsx)(`div`,{className:`mt-1`,children:e.modifiedValue||e.originalValue||(0,y.jsx)(`span`,{className:`text-muted-foreground italic`,children:`(无)`})})]},e.key))}):(0,y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:`原始`}),(0,y.jsx)(`div`,{className:`bg-muted/50 rounded-md p-2 text-xs font-mono max-h-[220px] overflow-auto space-y-1`,children:r.map(e=>(0,y.jsxs)(`div`,{className:S(e.status,`original`),children:[(0,y.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.displayKey,`:`]}),` `,e.originalValue||(0,y.jsx)(`span`,{className:`text-muted-foreground italic`,children:`(无)`})]},`original-${e.key}`))})]}),(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:`修改后`}),(0,y.jsx)(`div`,{className:`bg-muted/50 rounded-md p-2 text-xs font-mono max-h-[220px] overflow-auto space-y-1`,children:r.map(e=>(0,y.jsxs)(`div`,{className:S(e.status,`modified`),children:[(0,y.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.displayKey,`:`]}),` `,e.modifiedValue||(0,y.jsx)(`span`,{className:`text-muted-foreground italic`,children:`(无)`})]},`modified-${e.key}`))})]})]})}function be(e){switch(e){case`generating`:return`AI 正在流式生成修复代码`;case`saving`:return`正在保存修复后的插件代码`;case`reloading`:return`正在热加载插件`;case`retesting`:return`正在重新执行插件测试`;default:return``}}function C({open:e=!1,onOpenChange:t,embedded:n=!1,pluginId:i,pluginName:b,hooks:x,onPluginFixed:S}){let[C,xe]=(0,v.useState)(!1),[w,T]=(0,v.useState)(!1),[Se,Ce]=(0,v.useState)(`https://365.wps.cn/home`),[we,Te]=(0,v.useState)(`GET`),[E,D]=(0,v.useState)(`standalone`),[O,k]=(0,v.useState)(null),[A,Ee]=(0,v.useState)(`split`),[j,De]=(0,v.useState)(`inline`),[M,N]=(0,v.useState)(null),[P,F]=(0,v.useState)(``),[I,L]=(0,v.useState)(``),[R,Oe]=(0,v.useState)(!1),[z,B]=(0,v.useState)(null),[V,H]=(0,v.useState)(``),[ke,U]=(0,v.useState)(`normal`),[W,Ae]=(0,v.useState)(``),[G,K]=(0,v.useState)(`idle`),q=ie(),J=ne(q),je=J?{provider:J.provider,apiKey:J.apiKey,baseUrl:J.baseUrl,model:J.model}:{provider:q.provider,apiKey:q.apiKey,baseUrl:q.baseUrl,model:q.model},Y=re(q),X=i.startsWith(`local.`)?`${i.slice(6)}.js`:``,Z=(0,v.useCallback)(async()=>{if(!X||!e){F(``),L(``),B(null);return}Oe(!0),B(null);try{let e=await fetch(`/api/plugins/custom/${encodeURIComponent(X)}/code`);if(!e.ok){let t=await e.json();throw Error(t.error||`读取插件源码失败`)}let t=await e.json();F(t.code||``),!w&&!V&&L(t.code||``)}catch(e){F(``),L(``),B(e instanceof Error?e.message:`读取插件源码失败`)}finally{Oe(!1)}},[X,w,V,e]);(0,v.useEffect)(()=>{Z()},[Z]);let Q=(0,v.useMemo)(()=>{let e=[];return O?.error&&e.push({hookName:`test`,message:O.error}),Object.entries(O?.hookResults||{}).forEach(([t,n])=>{n?.status===`error`&&e.push({hookName:t,message:n.error||`未知错误`,stack:n.stack})}),O?.realRequest?.fetchError&&e.push({hookName:`fetch`,message:O.realRequest.fetchError}),e},[O]),Me=Q.length>0&&!!X,Ne=!!I&&!!(V||G===`idle`&&I&&P&&I!==P),Pe=async(e,t,n)=>{K(`saving`);let r=await fetch(`/api/plugins/custom/${encodeURIComponent(X)}/code`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({code:e})});if(!r.ok){let e=await r.json();throw Error(e.error||`保存修复后的代码失败`)}K(`reloading`);let i=await fetch(`/api/plugins/reload`,{method:`POST`});if(!i.ok){let e=await i.json().catch(()=>({error:`热加载失败`}));throw Error(e.error||`热加载失败`)}F(e),H(e),U(`diff`),window.dispatchEvent(new CustomEvent(`plugins-custom-updated`)),S?.(),n&&(K(`retesting`),await Fe()),N({status:`success`,message:t}),K(`idle`)},Fe=async()=>{xe(!0),k(null),N(null);try{let e=await fetch(`/api/plugins/test`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pluginId:i,url:Se,method:we,integrated:E===`integrated`})});if(!e.ok){let t=await e.json();throw Error(t.error||`测试失败`)}k((await e.json()).results)}catch(e){k({error:e instanceof Error?e.message:`测试失败`})}finally{xe(!1)}},$=(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)(pe,{className:`px-6 pt-6 pb-4`,children:[(0,y.jsxs)(me,{className:`flex items-center gap-2`,children:[(0,y.jsx)(h,{className:`h-5 w-5`}),`测试插件: `,b]}),(0,y.jsx)(oe,{children:`发起真实 HTTP 请求,在请求/响应过程中运行插件代码`})]}),(0,y.jsx)(p,{}),(0,y.jsxs)(`div`,{className:`app-panel-content`,children:[(0,y.jsxs)(`div`,{className:`app-section`,children:[(0,y.jsxs)(`div`,{className:`app-field-group`,children:[(0,y.jsx)(f,{htmlFor:`testUrl`,children:`请求 URL`}),(0,y.jsx)(ae,{id:`testUrl`,value:Se,onChange:e=>Ce(e.target.value),placeholder:`https://example.com/page`,disabled:C})]}),(0,y.jsxs)(`div`,{className:`app-field-group`,children:[(0,y.jsx)(f,{children:`HTTP 方法`}),(0,y.jsx)(`div`,{className:`flex gap-2`,children:[`GET`,`POST`,`PUT`,`DELETE`].map(e=>(0,y.jsx)(r,{type:`button`,variant:we===e?`selected`:`outline`,size:`sm`,onClick:()=>Te(e),disabled:C,children:e},e))})]}),(0,y.jsxs)(`div`,{className:`app-field-group`,children:[(0,y.jsx)(f,{children:`测试模式`}),(0,y.jsxs)(`div`,{className:`flex gap-2 flex-wrap`,children:[(0,y.jsx)(r,{type:`button`,variant:E===`standalone`?`selected`:`outline`,size:`sm`,onClick:()=>D(`standalone`),disabled:C,title:`直接请求 URL,不走路由与 Mock,便于排查插件自身逻辑`,children:`单独测试`}),(0,y.jsx)(r,{type:`button`,variant:E===`integrated`?`selected`:`outline`,size:`sm`,onClick:()=>D(`integrated`),disabled:C,title:`与真实代理一致:先路由解析、Mock 匹配,再请求,便于排查整体链路`,children:`集成测试`})]}),(0,y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:E===`standalone`?`直接请求上述 URL,不经过路由规则和 Mock,适合验证插件逻辑。`:`先按路由规则解析目标、匹配 Mock,再请求,与经代理的真实请求一致,适合排查链路问题。`})]}),(0,y.jsx)(`div`,{className:`bg-blue-50 dark:bg-blue-950/20 border border-blue-200 dark:border-blue-900 rounded-md p-3`,children:(0,y.jsxs)(`p`,{className:`text-xs text-blue-700 dark:text-blue-300`,children:[(0,y.jsx)(`strong`,{children:`测试流程:`}),` 发起真实请求 → 获取服务器响应 → 运行插件 Hook(`,x.join(`, `),`)→ 展示对比结果`]})})]}),!!X&&(0,y.jsxs)(`div`,{className:`space-y-3`,children:[(0,y.jsx)(p,{}),(0,y.jsxs)(`div`,{className:`space-y-2`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,y.jsxs)(`h3`,{className:`text-sm font-medium flex items-center gap-2`,children:[(0,y.jsx)(se,{className:`h-4 w-4`}),`插件代码`]}),(0,y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,y.jsx)(l,{value:ke,onValueChange:e=>U(e),children:(0,y.jsxs)(u,{className:`h-7`,children:[(0,y.jsx)(d,{value:`normal`,className:`px-2 text-xs`,children:`正常视图`}),(0,y.jsx)(d,{value:`diff`,className:`px-2 text-xs`,disabled:!Ne,children:`Diff 视图`})]})}),(0,y.jsx)(g,{variant:`outline`,className:`text-xs font-normal`,children:X}),(0,y.jsx)(r,{size:`sm`,variant:`ghost`,onClick:Z,disabled:R||w,children:R?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(m,{className:`h-4 w-4 mr-1 animate-spin`}),`读取中`]}):(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(c,{className:`h-4 w-4 mr-1`}),`刷新代码`]})})]})]}),z?(0,y.jsx)(`div`,{className:`rounded-md border border-red-200 bg-red-50/80 p-3 text-sm text-red-700 dark:border-red-900 dark:bg-red-950/20 dark:text-red-300`,children:z}):ke===`diff`&&Ne?(0,y.jsxs)(`div`,{className:`space-y-2`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`左侧是原代码,右侧是 AI 修复后的代码`}),G!==`idle`&&(0,y.jsx)(g,{variant:`outline`,className:`text-xs font-normal`,children:be(G)})]}),(0,y.jsx)(ge,{original:I||P,modified:V||P,language:`javascript`,minHeight:`320px`})]}):(0,y.jsx)(he,{value:w&&V?V:P,onChange:()=>{},language:`javascript`,readOnly:!0,minHeight:`260px`}),(0,y.jsxs)(`div`,{className:`space-y-2 pt-2`,children:[(0,y.jsx)(f,{htmlFor:`plugin-extra-instruction`,children:`额外信息`}),(0,y.jsx)(_e,{id:`plugin-extra-instruction`,value:W,onChange:e=>Ae(e.target.value),placeholder:`例如:补充 onBeforeResponse 里对 JSON 响应的判空逻辑;保留现有 hooks 和 manifest,不要改插件 id。`,className:`min-h-[88px]`,disabled:w||R}),(0,y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`输入额外要求后,AI 会基于当前插件代码直接更新并热加载。`}),(0,y.jsx)(r,{size:`sm`,variant:`outline`,onClick:async()=>{if(!(!X||!W.trim()||!Y||w)){T(!0),N(null),H(``),L(P);try{K(`generating`);let e=await fetch(`/api/plugins/revise-stream`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({originalCode:P,instruction:W.trim(),requirement:{name:b,description:`根据额外要求更新插件 ${b},并保持 hooks 行为正确。Hooks: ${x.join(`, `)}`,hooks:x},aiConfig:je})});if(!e.ok){let t=await e.json();throw Error(t.error||`AI 更新代码失败`)}let t=e.body?.getReader(),n=new TextDecoder;if(!t)throw Error(`无法读取 AI 更新流`);let r=``,i=``;for(;;){let{done:e,value:a}=await t.read();if(e)break;i+=n.decode(a,{stream:!0});let o=i.split(`
|
|
2
2
|
`);i=o.pop()||``;for(let e of o){if(!e.startsWith(`data:`))continue;let t=e.slice(5).trim();if(t)try{let e=JSON.parse(t);if(e.status===`generating`)N({status:`success`,message:`AI 正在根据额外要求更新插件代码...`});else if(e.chunk)r=e.accumulated||`${r}${e.chunk}`,H(r),U(`diff`);else if(e.status===`success`)r=e.revisedCode||r,H(r),U(`diff`);else if(e.error)throw Error(e.error)}catch(e){if(e instanceof Error&&e.message!==`Unexpected end of JSON input`)throw e}}}if(!r||typeof r!=`string`)throw Error(`AI 未返回有效代码`);N({status:`success`,message:`AI 已生成更新后的代码,正在保存并热加载...`}),await Pe(r,`AI 已根据额外要求更新插件代码并完成热加载。`,!1),Ae(``)}catch(e){N({status:`error`,message:e instanceof Error?e.message:`AI 更新代码失败`})}finally{K(`idle`),T(!1)}}},disabled:!X||!W.trim()||!Y||w||R||!!z,children:w&&G!==`retesting`?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(m,{className:`h-4 w-4 mr-1 animate-spin`}),`AI 更新中...`]}):(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(ee,{className:`h-4 w-4 mr-1`}),`根据额外信息更新代码`]})})]})]})]})]}),O&&(0,y.jsxs)(`div`,{className:`space-y-3`,children:[(0,y.jsx)(p,{}),O.error?(0,y.jsx)(`div`,{className:`bg-red-50 dark:bg-red-950/20 border border-red-200 dark:border-red-900 rounded-md p-3`,children:(0,y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,y.jsx)(s,{className:`h-4 w-4 text-red-600 mt-0.5 shrink-0`}),(0,y.jsx)(`span`,{className:`text-sm text-red-700 dark:text-red-300`,children:O.error})]})}):(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)(`div`,{className:`flex flex-wrap gap-4 items-center rounded-md border bg-muted/20 px-3 py-2`,children:[(0,y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Header 对比`}),(0,y.jsx)(l,{value:A,onValueChange:e=>Ee(e),children:(0,y.jsxs)(u,{className:`h-7`,children:[(0,y.jsx)(d,{value:`split`,className:`px-2 text-xs`,children:`分栏`}),(0,y.jsx)(d,{value:`inline`,className:`px-2 text-xs`,children:`行内`})]})})]}),(0,y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Body 对比`}),(0,y.jsx)(l,{value:j,onValueChange:e=>De(e),children:(0,y.jsxs)(u,{className:`h-7`,children:[(0,y.jsx)(d,{value:`inline`,className:`px-2 text-xs`,children:`行内`}),(0,y.jsx)(d,{value:`split`,className:`px-2 text-xs`,children:`分栏`})]})})]})]}),O.realRequest&&(0,y.jsxs)(`div`,{className:`space-y-2`,children:[(0,y.jsxs)(`h3`,{className:`text-sm font-medium flex items-center gap-2`,children:[(0,y.jsx)(fe,{className:`h-4 w-4`}),`真实请求`,O.realRequest.testMode&&(0,y.jsx)(g,{variant:`outline`,className:`text-xs font-normal`,children:O.realRequest.testMode===`integrated`?`集成测试`:`单独测试`})]}),(0,y.jsxs)(`div`,{className:`bg-muted/50 rounded-md p-3 text-xs space-y-1`,children:[(0,y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,y.jsx)(g,{variant:`outline`,className:`text-xs`,children:O.realRequest.method}),(0,y.jsx)(`span`,{className:`font-mono break-all`,children:O.realRequest.url})]}),O.realRequest.fetchError?(0,y.jsxs)(`div`,{className:`text-red-600 flex items-center gap-1 mt-1`,children:[(0,y.jsx)(s,{className:`h-3 w-3`}),`请求失败: `,O.realRequest.fetchError]}):(0,y.jsxs)(`div`,{className:`text-muted-foreground space-y-0.5`,children:[(0,y.jsxs)(`div`,{children:[`耗时: `,O.realRequest.fetchDuration,`ms`,O.originalResponse&&(0,y.jsxs)(y.Fragment,{children:[` · 状态码: `,(0,y.jsx)(g,{variant:`outline`,className:`text-xs`,children:O.originalResponse.statusCode}),` · 响应大小: `,O.originalResponse.bodyLength,` 字符`]})]}),(O.realRequest.targetResolved||O.realRequest.usedMock)&&(0,y.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-1`,children:[O.realRequest.targetResolved&&(0,y.jsx)(g,{variant:`outline`,className:`text-xs text-blue-600 border-blue-300`,children:`路由已改写`}),O.realRequest.usedMock&&(0,y.jsx)(g,{variant:`outline`,className:`text-xs text-orange-600 border-orange-300`,children:`已使用 Mock`})]})]})]})]}),(0,y.jsxs)(`div`,{className:`space-y-2`,children:[(0,y.jsxs)(`h3`,{className:`text-sm font-medium flex items-center gap-2`,children:[(0,y.jsx)(h,{className:`h-4 w-4`}),`Hook 执行结果`]}),Object.keys(O.hookResults||{}).length===0?(0,y.jsx)(`div`,{className:`text-xs text-muted-foreground bg-muted/50 rounded-md p-3`,children:`没有 Hook 被执行`}):(0,y.jsx)(`div`,{className:`space-y-2`,children:Object.entries(O.hookResults||{}).map(([e,t])=>(0,y.jsxs)(`div`,{className:`border rounded-md p-3 ${t.status===`success`?`bg-green-50 dark:bg-green-950/20 border-green-200 dark:border-green-900`:`bg-red-50 dark:bg-red-950/20 border-red-200 dark:border-red-900`}`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.status===`success`?(0,y.jsx)(de,{className:`h-4 w-4 text-green-600`}):(0,y.jsx)(s,{className:`h-4 w-4 text-red-600`}),(0,y.jsx)(`span`,{className:`font-medium text-sm`,children:e})]}),t.duration!==void 0&&(0,y.jsxs)(g,{variant:`outline`,className:`text-xs`,children:[t.duration,`ms`]})]}),t.status===`error`&&(0,y.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,y.jsxs)(`div`,{className:`rounded-md border border-red-200 bg-red-100/60 px-2 py-2 text-xs text-red-800 dark:border-red-900 dark:bg-red-950/20 dark:text-red-300`,children:[(0,y.jsx)(`div`,{className:`font-medium mb-1`,children:`错误原因`}),(0,y.jsx)(`pre`,{className:`font-mono whitespace-pre-wrap break-all`,children:t.error})]}),t.stack&&(0,y.jsxs)(`details`,{className:`rounded-md border border-red-200 bg-background/60 px-2 py-2 text-xs dark:border-red-900`,children:[(0,y.jsx)(`summary`,{className:`cursor-pointer text-red-700 dark:text-red-300`,children:`查看错误堆栈`}),(0,y.jsx)(`pre`,{className:`font-mono whitespace-pre-wrap break-all mt-2 text-muted-foreground`,children:t.stack})]})]}),t.targetChanged&&(0,y.jsxs)(`div`,{className:`text-xs text-blue-700 mt-1 flex items-center gap-1`,children:[(0,y.jsx)(a,{className:`h-3 w-3`}),`Target 已修改为: `,t.targetChanged]})]},e))})]}),Q.length>0&&(0,y.jsxs)(`div`,{className:`space-y-2`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,y.jsxs)(`h3`,{className:`text-sm font-medium flex items-center gap-2`,children:[(0,y.jsx)(o,{className:`h-4 w-4 text-red-500`}),`错误详情`]}),(0,y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!Y&&(0,y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`AI 未配置,无法自动修复`}),(0,y.jsx)(r,{size:`sm`,variant:`outline`,onClick:async()=>{if(!(!Me||!Y)){T(!0),N(null),H(``),L(P);try{K(`generating`);let e={code:P};if(!e.code)throw Error(`插件源码为空,无法修复`);let t=Q.map(e=>`Hook: ${e.hookName}\nError: ${e.message}${e.stack?`\nStack:\n${e.stack}`:``}`).join(`
|
|
3
3
|
|
|
4
4
|
---
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,f as t,l as n,t as r,u as i}from"./button-BTToMaBW.js";import{t as a}from"./arrow-right-B4Mrlj2-.js";import{A as o,Q as s,W as c,a as l,lt as u,ot as d,z as f}from"./index-
|
|
1
|
+
import{a as e,f as t,l as n,t as r,u as i}from"./button-BTToMaBW.js";import{t as a}from"./arrow-right-B4Mrlj2-.js";import{A as o,Q as s,W as c,a as l,lt as u,ot as d,z as f}from"./index-DJ5BnqEk.js";var p=n(`locate-fixed`,[[`line`,{x1:`2`,x2:`5`,y1:`12`,y2:`12`,key:`bvdh0s`}],[`line`,{x1:`19`,x2:`22`,y1:`12`,y2:`12`,key:`1tbv5k`}],[`line`,{x1:`12`,x2:`12`,y1:`2`,y2:`5`,key:`11lu5j`}],[`line`,{x1:`12`,x2:`12`,y1:`19`,y2:`22`,key:`x3vr5v`}],[`circle`,{cx:`12`,cy:`12`,r:`7`,key:`fim9np`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),m=t(i(),1),h=e();function g({rules:e,activeFileName:t,embedded:n=!1,onRevealRule:i}){let[g,_]=(0,m.useState)(``),[v,y]=(0,m.useState)(!1),[b,x]=(0,m.useState)(null),[S,C]=(0,m.useState)(null),w=(0,m.useMemo)(()=>l(e),[e]),T=n?`global-route-preview-url`:`route-preview-url`;(0,m.useEffect)(()=>{if(!n)return;let e=window.requestAnimationFrame(()=>{document.getElementById(T)?.focus()});return()=>window.cancelAnimationFrame(e)},[n,T]);let E=(0,m.useCallback)(async()=>{let e=g.trim();if(!e){C(`请输入待预览的 URL`),x(null);return}y(!0),C(null);try{let t=await fetch(`/api/rules/preview`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({url:e,rulesText:w})}),n=await t.json();if(!t.ok)throw Error(n?.error||`预览失败`);x(n)}catch(e){x(null),C(e instanceof Error?e.message:`预览失败`)}finally{y(!1)}},[g,w]),D=(0,m.useCallback)(e=>{e.key===`Enter`&&E()},[E]);return(0,h.jsxs)(`div`,{className:n?`app-panel-content h-full`:`rounded-lg border bg-card p-4 space-y-3`,children:[(0,h.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,h.jsxs)(`div`,{className:`space-y-1`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(s,{className:`h-4 w-4 text-primary`}),(0,h.jsx)(`h3`,{className:`text-sm font-semibold`,children:`URL 预览`})]}),(0,h.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`输入一个请求 URL,后端会用当前编辑中的规则直接计算真实转发地址。`})]}),t&&(0,h.jsxs)(f,{variant:`outline`,className:`text-[11px] font-normal`,children:[(0,h.jsx)(u,{className:`h-3 w-3 mr-1`}),t]})]}),(0,h.jsxs)(`div`,{className:`flex gap-2`,children:[(0,h.jsx)(o,{id:T,value:g,onChange:e=>_(e.target.value),onKeyDown:D,placeholder:`https://solution.wps.cn/docs/price/detail.html?source=navbar`,className:`h-9 font-mono text-xs`}),(0,h.jsx)(r,{onClick:E,disabled:v,className:`h-9 shrink-0`,children:v?(0,h.jsx)(d,{className:`h-4 w-4 animate-spin`}):`预览`})]}),n&&(0,h.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`使用当前编辑区内尚未保存的规则进行计算,结果会与路由规则页的预览保持一致。`}),S&&(0,h.jsx)(`div`,{className:`rounded-md border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-800`,children:(0,h.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(c,{className:`h-3.5 w-3.5 shrink-0`}),(0,h.jsx)(`span`,{children:S})]})}),b&&(0,h.jsxs)(`div`,{className:n?`min-h-0 flex-1 space-y-3 overflow-auto rounded-md border bg-muted/20 p-3`:`space-y-3 rounded-md border bg-muted/20 p-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(f,{className:b.matched?`bg-green-100 text-green-800 border-green-200`:`bg-blue-100 text-blue-800 border-blue-200`,children:b.matched?`已命中规则`:`未命中规则`}),b.matchedRule&&(0,h.jsx)(f,{variant:`outline`,className:`text-[11px] font-normal`,children:b.matchedRule.kind})]}),(0,h.jsxs)(`div`,{className:`space-y-1`,children:[(0,h.jsx)(`div`,{className:`text-[11px] uppercase tracking-wide text-muted-foreground`,children:`真实 URL`}),(0,h.jsx)(`div`,{className:`rounded-md border bg-background px-3 py-2 font-mono text-xs break-all`,children:b.resolvedUrl})]}),b.matchedRule&&(0,h.jsxs)(`div`,{className:`space-y-1`,children:[(0,h.jsx)(`div`,{className:`text-[11px] uppercase tracking-wide text-muted-foreground`,children:`命中规则`}),(0,h.jsxs)(`div`,{className:`flex items-stretch gap-2`,children:[(0,h.jsxs)(`div`,{className:`min-w-0 flex-1 rounded-md border bg-background px-3 py-2 font-mono text-xs break-all`,children:[b.matchedRule.pattern,(0,h.jsx)(`span`,{className:`text-muted-foreground`,children:` → `}),b.matchedRule.target]}),i&&(0,h.jsxs)(r,{type:`button`,variant:`outline`,size:`sm`,className:`h-auto shrink-0 gap-1.5 px-3 text-xs`,onClick:()=>b.matchedRule&&i(b.matchedRule),title:`在路由规则页面定位这条规则`,children:[(0,h.jsx)(p,{className:`h-3.5 w-3.5`}),`定位`]})]})]}),(0,h.jsxs)(`div`,{className:`space-y-1`,children:[(0,h.jsx)(`div`,{className:`text-[11px] uppercase tracking-wide text-muted-foreground`,children:`说明`}),(0,h.jsx)(`div`,{className:`space-y-1 rounded-md border bg-background px-3 py-2 text-xs`,children:b.notes.length>0?b.notes.map(e=>(0,h.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(a,{className:`h-3 w-3 text-muted-foreground shrink-0`}),(0,h.jsx)(`span`,{children:e})]},e)):(0,h.jsx)(`span`,{className:`text-muted-foreground`,children:`无`})})]})]})]})}export{g as RoutePreview};
|
package/web/dist/assets/{rule-ai-assistant-panel-DsJ1sdXd.js → rule-ai-assistant-panel-LWDaNQKt.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as e,f as t,t as n,u as r}from"./button-BTToMaBW.js";import{t as i}from"./wand-sparkles-wkul5vje.js";import{i as a,o,r as s}from"./ai-config-store-DQXVJVn_.js";import{X as c,a as l,i as u,ot as d,z as f}from"./index-
|
|
1
|
+
import{a as e,f as t,t as n,u as r}from"./button-BTToMaBW.js";import{t as i}from"./wand-sparkles-wkul5vje.js";import{i as a,o,r as s}from"./ai-config-store-DQXVJVn_.js";import{X as c,a as l,i as u,ot as d,z as f}from"./index-DJ5BnqEk.js";import{n as p,t as m}from"./alert-Bve02Ufr.js";import{t as h}from"./textarea-vuxJwU0x.js";var g=t(r(),1);function _(e){return e.replace(/^```[a-z]*\n?/i,``).replace(/\n?```$/i,``).trim()}function v(){let e=s(),t=a(e);return t?{enabled:e.enabled,provider:t.provider,apiKey:t.apiKey,baseUrl:t.baseUrl,model:t.model}:e}function y(e,t){return{system:`你是 Meddle 的路由规则整理助手。你的任务是合并和精简用户的路由规则,在不改变语义的前提下尽量减少规则数量。
|
|
2
2
|
|
|
3
3
|
请严格遵守以下要求:
|
|
4
4
|
1. 只输出最终规则文本,不要输出解释、标题、Markdown 代码块或额外说明。
|