flex-mcp 1.1.9 → 1.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/api/configs.js +8 -1
  2. package/dist/api/configs.js.map +1 -1
  3. package/dist/api/index.d.ts.map +1 -1
  4. package/dist/api/index.js +3 -0
  5. package/dist/api/index.js.map +1 -1
  6. package/dist/api/update.d.ts +6 -0
  7. package/dist/api/update.d.ts.map +1 -0
  8. package/dist/api/update.js +269 -0
  9. package/dist/api/update.js.map +1 -0
  10. package/dist/db/schema.d.ts +0 -12
  11. package/dist/db/schema.d.ts.map +1 -1
  12. package/dist/db/schema.js +0 -1
  13. package/dist/db/schema.js.map +1 -1
  14. package/dist/mcp/aggregator.d.ts.map +1 -1
  15. package/dist/mcp/aggregator.js +3 -6
  16. package/dist/mcp/aggregator.js.map +1 -1
  17. package/dist/mcp/tool-sync.d.ts.map +1 -1
  18. package/dist/mcp/tool-sync.js +0 -1
  19. package/dist/mcp/tool-sync.js.map +1 -1
  20. package/dist/script/context.d.ts.map +1 -1
  21. package/dist/script/context.js +10 -0
  22. package/dist/script/context.js.map +1 -1
  23. package/dist/types/index.d.ts +1 -1
  24. package/dist/types/index.d.ts.map +1 -1
  25. package/dist/update.d.ts.map +1 -1
  26. package/dist/update.js +37 -8
  27. package/dist/update.js.map +1 -1
  28. package/dist/web/assets/{Blank-BAn70pKV.js → Blank-DnwEW0VT.js} +1 -1
  29. package/dist/web/assets/{Configs-C6QxaALX.js → Configs-Bq1LRu7c.js} +1 -1
  30. package/dist/web/assets/{Dashboard-CC6Oo381.js → Dashboard-DG4KlU_v.js} +1 -1
  31. package/dist/web/assets/InitScriptEditor-BpsNM3mj.js +509 -0
  32. package/dist/web/assets/Layout-CZunjis7.js +1 -0
  33. package/dist/web/assets/Layout-DuBl1mVJ.js +1 -0
  34. package/dist/web/assets/{Login-zgQ_fCXm.js → Login-CV4pyxSI.js} +1 -1
  35. package/dist/web/assets/{Login-BxCS6qf-.js → Login-Drzps0QW.js} +1 -1
  36. package/dist/web/assets/Users-zsruR1wp.js +1 -0
  37. package/dist/web/assets/{index-DAOSS2K-.js → index-mIcNgFiY.js} +3 -3
  38. package/dist/web/assets/style-BdM4weEm.css +1 -0
  39. package/dist/web/index.html +2 -2
  40. package/package.json +1 -1
  41. package/dist/web/assets/InitScriptEditor-DzzTB5Qk.js +0 -679
  42. package/dist/web/assets/Layout-BOxnvITD.js +0 -1
  43. package/dist/web/assets/Layout-CNq36nXL.js +0 -1
  44. package/dist/web/assets/Users-68dlwZ5K.js +0 -1
  45. package/dist/web/assets/style-C2LUa6XO.css +0 -1
@@ -0,0 +1,509 @@
1
+ import{a1 as io,r as A,y as ue,d as ht,s as At,U as co,D as ke,c as q,o as F,u as Dt,p as Te,m as ce,f as m,b as o,w as d,g as p,B as G,a2 as uo,e as Wt,G as vt,h as I,F as dt,v as pt,A as De,t as ne,Q as Xe,Z as po,a3 as vo,K as Zt,L as gt,a4 as Et,a5 as go,a6 as Ft,a7 as Ut,N as Qt,j as fe,k as be,O as Yt,a8 as $t,M as Le,z as Ae,H as Xt,a9 as je,S as mo,aa as fo,l as ct,ab as ho,Y as yo,R as Fe,E as Pt,ac as Mt,n as ve,I as Bt,_ as Jt,ad as wo,J as bo}from"./index-mIcNgFiY.js";import{_ as zt}from"./_plugin-vue_export-helper-DlAUqK2U.js";const Cr=io("config",()=>{const t=A(null),a=A(!1);async function s(){var $,P;a.value=!0;try{const R=await ue.get("/configs/me");return t.value=R.data.data,t.value}catch(R){throw new Error(((P=($=R.response)==null?void 0:$.data)==null?void 0:P.error)||"Failed to fetch config")}finally{a.value=!1}}async function c($){var P,R;a.value=!0;try{const V=await ue.get(`/configs/user/${$}`);return t.value=V.data.data,t.value}catch(V){throw new Error(((R=(P=V.response)==null?void 0:P.data)==null?void 0:R.error)||"Failed to fetch user config")}finally{a.value=!1}}async function u($){var P,R;a.value=!0;try{const V=await ue.put("/configs/me",$);return t.value=V.data.data,t.value}catch(V){throw new Error(((R=(P=V.response)==null?void 0:P.data)==null?void 0:R.error)||"Failed to update config")}finally{a.value=!1}}async function h($,P){var R,V;a.value=!0;try{const D=await ue.put(`/configs/user/${$}`,P);return t.value=D.data.data,t.value}catch(D){throw new Error(((V=(R=D.response)==null?void 0:R.data)==null?void 0:V.error)||"Failed to update user config")}finally{a.value=!1}}function j($){const P={...$,variables:$.variables.map(R=>({...R,value:R.isSecret?`{{${R.name}}}`:R.value}))};return JSON.stringify(P,null,2)}function k($){try{const P=JSON.parse($);if(!P.name||!Array.isArray(P.components)||!Array.isArray(P.customTools))throw new Error("Invalid config format");return P}catch(P){throw new Error(`Failed to parse config: ${P.message}`)}}return{currentConfig:t,loading:a,fetchConfig:s,fetchUserConfig:c,updateConfig:u,updateUserConfig:h,exportConfig:j,importConfig:k}});function Qe(){if(typeof globalThis<"u"&&"crypto"in globalThis){const t=globalThis.crypto;if(t&&typeof t.randomUUID=="function")return t.randomUUID()}return`${Date.now()}-${Math.random().toString(36).substring(2,11)}`}function It(t){return t==null?!1:typeof t=="boolean"?t:typeof t=="string"?t.trim()!=="":typeof t=="number"?t!==0:Array.isArray(t)?t.length>0:typeof t=="object"?Object.keys(t).length>0:!!t}function ko(t,a){let s=t;const c=/\{\{#if\s+(\w+)\}\}([\s\S]*?)(?:\{\{else\}\}([\s\S]*?))?\{\{\/if\}\}/g;s=s.replace(c,(h,j,k,$)=>{const P=a[j];return It(P)?k||"":$||""});const u=/\{\{#ifnot\s+(\w+)\}\}([\s\S]*?)(?:\{\{else\}\}([\s\S]*?))?\{\{\/ifnot\}\}/g;return s=s.replace(u,(h,j,k,$)=>{const P=a[j];return It(P)?$||"":k||""}),s}function Co(t,a){return t.replace(/\{\{(\w+)\}\}/g,(s,c)=>{const u=a[c];return u!=null?String(u):s})}function xr(t,a){let s=ko(t,a);return s=Co(s,a),s}function Rt(t,a){(a==null||a>t.length)&&(a=t.length);for(var s=0,c=Array(a);s<a;s++)c[s]=t[s];return c}function xo(t){if(Array.isArray(t))return t}function To(t,a,s){return(a=Mo(a))in t?Object.defineProperty(t,a,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[a]=s,t}function So(t,a){var s=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(s!=null){var c,u,h,j,k=[],$=!0,P=!1;try{if(h=(s=s.call(t)).next,a!==0)for(;!($=(c=h.call(s)).done)&&(k.push(c.value),k.length!==a);$=!0);}catch(R){P=!0,u=R}finally{try{if(!$&&s.return!=null&&(j=s.return(),Object(j)!==j))return}finally{if(P)throw u}}return k}}function $o(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
2
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Vt(t,a){var s=Object.keys(t);if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(t);a&&(c=c.filter(function(u){return Object.getOwnPropertyDescriptor(t,u).enumerable})),s.push.apply(s,c)}return s}function Lt(t){for(var a=1;a<arguments.length;a++){var s=arguments[a]!=null?arguments[a]:{};a%2?Vt(Object(s),!0).forEach(function(c){To(t,c,s[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(s)):Vt(Object(s)).forEach(function(c){Object.defineProperty(t,c,Object.getOwnPropertyDescriptor(s,c))})}return t}function Po(t,a){if(t==null)return{};var s,c,u=jo(t,a);if(Object.getOwnPropertySymbols){var h=Object.getOwnPropertySymbols(t);for(c=0;c<h.length;c++)s=h[c],a.indexOf(s)===-1&&{}.propertyIsEnumerable.call(t,s)&&(u[s]=t[s])}return u}function jo(t,a){if(t==null)return{};var s={};for(var c in t)if({}.hasOwnProperty.call(t,c)){if(a.indexOf(c)!==-1)continue;s[c]=t[c]}return s}function No(t,a){return xo(t)||So(t,a)||Ao(t,a)||$o()}function Oo(t,a){if(typeof t!="object"||!t)return t;var s=t[Symbol.toPrimitive];if(s!==void 0){var c=s.call(t,a);if(typeof c!="object")return c;throw new TypeError("@@toPrimitive must return a primitive value.")}return(a==="string"?String:Number)(t)}function Mo(t){var a=Oo(t,"string");return typeof a=="symbol"?a:a+""}function Ao(t,a){if(t){if(typeof t=="string")return Rt(t,a);var s={}.toString.call(t).slice(8,-1);return s==="Object"&&t.constructor&&(s=t.constructor.name),s==="Map"||s==="Set"?Array.from(t):s==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(s)?Rt(t,a):void 0}}function Do(t,a,s){return a in t?Object.defineProperty(t,a,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[a]=s,t}function qt(t,a){var s=Object.keys(t);if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(t);a&&(c=c.filter(function(u){return Object.getOwnPropertyDescriptor(t,u).enumerable})),s.push.apply(s,c)}return s}function Ht(t){for(var a=1;a<arguments.length;a++){var s=arguments[a]!=null?arguments[a]:{};a%2?qt(Object(s),!0).forEach(function(c){Do(t,c,s[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(s)):qt(Object(s)).forEach(function(c){Object.defineProperty(t,c,Object.getOwnPropertyDescriptor(s,c))})}return t}function zo(){for(var t=arguments.length,a=new Array(t),s=0;s<t;s++)a[s]=arguments[s];return function(c){return a.reduceRight(function(u,h){return h(u)},c)}}function Ye(t){return function a(){for(var s=this,c=arguments.length,u=new Array(c),h=0;h<c;h++)u[h]=arguments[h];return u.length>=t.length?t.apply(this,u):function(){for(var j=arguments.length,k=new Array(j),$=0;$<j;$++)k[$]=arguments[$];return a.apply(s,[].concat(u,k))}}}function mt(t){return{}.toString.call(t).includes("Object")}function _o(t){return!Object.keys(t).length}function et(t){return typeof t=="function"}function Eo(t,a){return Object.prototype.hasOwnProperty.call(t,a)}function Fo(t,a){return mt(a)||ze("changeType"),Object.keys(a).some(function(s){return!Eo(t,s)})&&ze("changeField"),a}function Uo(t){et(t)||ze("selectorType")}function Bo(t){et(t)||mt(t)||ze("handlerType"),mt(t)&&Object.values(t).some(function(a){return!et(a)})&&ze("handlersType")}function Jo(t){t||ze("initialIsRequired"),mt(t)||ze("initialType"),_o(t)&&ze("initialContent")}function Io(t,a){throw new Error(t[a]||t.default)}var Ro={initialIsRequired:"initial state is required",initialType:"initial state should be an object",initialContent:"initial state shouldn't be an empty object",handlerType:"handler should be an object or a function",handlersType:"all handlers should be a functions",selectorType:"selector should be a function",changeType:"provided value of changes should be an object",changeField:'it seams you want to change a field in the state which is not specified in the "initial" state',default:"an unknown error accured in `state-local` package"},ze=Ye(Io)(Ro),ut={changes:Fo,selector:Uo,handler:Bo,initial:Jo};function Vo(t){var a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};ut.initial(t),ut.handler(a);var s={current:t},c=Ye(Ho)(s,a),u=Ye(qo)(s),h=Ye(ut.changes)(t),j=Ye(Lo)(s);function k(){var P=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(R){return R};return ut.selector(P),P(s.current)}function $(P){zo(c,u,h,j)(P)}return[k,$]}function Lo(t,a){return et(a)?a(t.current):a}function qo(t,a){return t.current=Ht(Ht({},t.current),a),a}function Ho(t,a,s){return et(a)?a(t.current):Object.keys(s).forEach(function(c){var u;return(u=a[c])===null||u===void 0?void 0:u.call(a,t.current[c])}),s}var Ko={create:Vo},Go={paths:{vs:"https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs"}};function Wo(t){return function a(){for(var s=this,c=arguments.length,u=new Array(c),h=0;h<c;h++)u[h]=arguments[h];return u.length>=t.length?t.apply(this,u):function(){for(var j=arguments.length,k=new Array(j),$=0;$<j;$++)k[$]=arguments[$];return a.apply(s,[].concat(u,k))}}}function Zo(t){return{}.toString.call(t).includes("Object")}function Qo(t){return t||Kt("configIsRequired"),Zo(t)||Kt("configType"),t.urls?(Yo(),{paths:{vs:t.urls.monacoBase}}):t}function Yo(){console.warn(eo.deprecation)}function Xo(t,a){throw new Error(t[a]||t.default)}var eo={configIsRequired:"the configuration object is required",configType:"the configuration object should be an object",default:"an unknown error accured in `@monaco-editor/loader` package",deprecation:`Deprecation warning!
3
+ You are using deprecated way of configuration.
4
+
5
+ Instead of using
6
+ monaco.config({ urls: { monacoBase: '...' } })
7
+ use
8
+ monaco.config({ paths: { vs: '...' } })
9
+
10
+ For more please check the link https://github.com/suren-atoyan/monaco-loader#config
11
+ `},Kt=Wo(Xo)(eo),en={config:Qo},tn=function(){for(var a=arguments.length,s=new Array(a),c=0;c<a;c++)s[c]=arguments[c];return function(u){return s.reduceRight(function(h,j){return j(h)},u)}};function to(t,a){return Object.keys(a).forEach(function(s){a[s]instanceof Object&&t[s]&&Object.assign(a[s],to(t[s],a[s]))}),Lt(Lt({},t),a)}var on={type:"cancelation",msg:"operation is manually canceled"};function jt(t){var a=!1,s=new Promise(function(c,u){t.then(function(h){return a?u(on):c(h)}),t.catch(u)});return s.cancel=function(){return a=!0},s}var nn=["monaco"],sn=Ko.create({config:Go,isInitialized:!1,resolve:null,reject:null,monaco:null}),oo=No(sn,2),tt=oo[0],yt=oo[1];function rn(t){var a=en.config(t),s=a.monaco,c=Po(a,nn);yt(function(u){return{config:to(u.config,c),monaco:s}})}function an(){var t=tt(function(a){var s=a.monaco,c=a.isInitialized,u=a.resolve;return{monaco:s,isInitialized:c,resolve:u}});if(!t.isInitialized){if(yt({isInitialized:!0}),t.monaco)return t.resolve(t.monaco),jt(Nt);if(window.monaco&&window.monaco.editor)return no(window.monaco),t.resolve(window.monaco),jt(Nt);tn(ln,un)(dn)}return jt(Nt)}function ln(t){return document.body.appendChild(t)}function cn(t){var a=document.createElement("script");return t&&(a.src=t),a}function un(t){var a=tt(function(c){var u=c.config,h=c.reject;return{config:u,reject:h}}),s=cn("".concat(a.config.paths.vs,"/loader.js"));return s.onload=function(){return t()},s.onerror=a.reject,s}function dn(){var t=tt(function(s){var c=s.config,u=s.resolve,h=s.reject;return{config:c,resolve:u,reject:h}}),a=window.require;a.config(t.config),a(["vs/editor/editor.main"],function(s){var c=s.m||s;no(c),t.resolve(c)},function(s){t.reject(s)})}function no(t){tt().monaco||yt({monaco:t})}function pn(){return tt(function(t){var a=t.monaco;return a})}var Nt=new Promise(function(t,a){return yt({resolve:t,reject:a})}),vn={config:rn,init:an,__getMonacoInstance:pn};const ft=ht({__name:"MonacoEditor",props:{modelValue:{},language:{},theme:{},options:{},extraLibs:{}},emits:["update:modelValue","save","change"],setup(t,{emit:a}){const s=t,c=a,u=A();let h=null,j=null,k=null,$=!1,P=null;const R=A(new Map);function V(D){if(!j)return;R.value.forEach(H=>{H.dispose()}),R.value.clear();const Y=(s.language||"typescript")==="typescript"?j.languages.typescript.typescriptDefaults:j.languages.typescript.javascriptDefaults;Y.setDiagnosticsOptions({noSemanticValidation:!1,noSyntaxValidation:!1}),Y.setCompilerOptions({target:j.languages.typescript.ScriptTarget.ES2020,allowNonTsExtensions:!0,strict:!0}),Y.setInlayHintsOptions({includeInlayParameterNameHints:"all"}),D.forEach(H=>{const z=H.filePath||`file:///lib-${Date.now()}.d.ts`,U=Y.addExtraLib(H.content,z);R.value.set(z,U)})}return At(async()=>{var L,Y,H;j=await vn.init(),s.extraLibs&&V(s.extraLibs);const D=s.language||"typescript";k&&k.dispose(),k=j.languages.registerCompletionItemProvider(D,{provideCompletionItems:()=>({suggestions:[]}),triggerCharacters:['"',"'"]}),h=j.editor.create(u.value,{value:s.modelValue,language:D,theme:s.theme||"vs-dark",automaticLayout:!0,minimap:{enabled:!0},fontSize:14,tabSize:2,readOnly:!1,...s.options,quickSuggestions:{other:!0,comments:!1,strings:!0,...(L=s.options)==null?void 0:L.quickSuggestions},suggestOnTriggerCharacters:((Y=s.options)==null?void 0:Y.suggestOnTriggerCharacters)??!0,wordWrap:((H=s.options)==null?void 0:H.wordWrap)??"off"}),h.onDidChangeModelContent(z=>{var B;if($)return;const U=h.getValue();c("update:modelValue",U),c("change",U);const C=(B=z.changes)==null?void 0:B[z.changes.length-1];C&&(C.text==='"'||C.text==="'")&&setTimeout(()=>{h&&h.trigger("","editor.action.triggerSuggest",{})},100)}),h.addCommand(j.KeyMod.CtrlCmd|j.KeyCode.KeyS,()=>{c("save")}),P=z=>{if(!(!h||!h.hasTextFocus())){if((z.metaKey||z.ctrlKey)&&z.key==="z"&&!z.shiftKey){z.preventDefault(),z.stopPropagation();const U=h.getModel();return U&&U.canUndo()&&U.undo(),!1}if((z.metaKey||z.ctrlKey)&&z.key==="z"&&z.shiftKey){z.preventDefault(),z.stopPropagation();const U=h.getModel();return U&&U.canRedo()&&U.redo(),!1}if((z.metaKey||z.ctrlKey)&&z.key==="y"){z.preventDefault(),z.stopPropagation();const U=h.getModel();return U&&U.canRedo()&&U.redo(),!1}}},document.addEventListener("keydown",P,!0)}),co(()=>{k==null||k.dispose(),h==null||h.dispose(),P&&(document.removeEventListener("keydown",P,!0),P=null)}),ke(()=>s.modelValue,D=>{if(!h)return;if(h.getValue()!==D){$=!0;try{const Y=h.getModel();if(Y){const H=Y.getFullModelRange();h.executeEdits("external-update",[{range:H,text:D}]),h.pushUndoStop();const z=Y.getLineCount(),U=Y.getLineMaxColumn(z);h.setPosition({lineNumber:z,column:U})}}finally{setTimeout(()=>{$=!1},0)}}}),ke(()=>s.extraLibs,(D,L)=>{if(!D||!j||!(!L||D.length!==L.length||D.some((z,U)=>{const C=L[U];return!C||z.content!==C.content||z.filePath!==C.filePath})))return;V(D);const H=h==null?void 0:h.getModel();H&&(j.editor.setModelMarkers(H,"typescript",[]),setTimeout(()=>{h&&H&&H.getValue()===H.getValue()&&H.forceTokenization(H.getLineCount())},100))},{deep:!0,immediate:!1}),(D,L)=>(F(),q("div",{ref_key:"editorContainer",ref:u,class:"w-full h-full min-h-[400px]"},null,512))}}),gn={class:"components-manager"},mn={key:0,class:"components-toolbar"},fn={class:"toolbar-actions"},hn={key:1},yn={class:"component-item"},wn={class:"component-main"},bn={class:"component-icon"},kn={class:"icon-circle"},Cn={class:"component-info"},xn={class:"component-title"},Tn={class:"name"},Sn={class:"component-actions"},$n={key:0,class:"component-tools"},Pn={key:2,class:"empty-state"},jn={class:"empty-state-content"},Nn={class:"empty-actions"},On={class:"modal-header"},Mn={class:"modal-title"},An={class:"modal-subtitle"},Dn={class:"modal-content-wrapper"},zn={class:"tab-pane-content"},_n={class:"mode-switcher"},En={class:"form-content"},Fn={class:"form-section"},Un={class:"form-grid"},Bn={key:0,class:"form-section"},Jn={class:"form-grid"},In={key:1,class:"form-section"},Rn={key:2,class:"form-section"},Vn={class:"json-content"},Ln={class:"editor-wrapper"},qn={class:"tab-pane-content tools-tab-content"},Hn={class:"tools-action-bar"},Kn={class:"tools-action-buttons"},Gn={key:0,class:"batch-actions"},Wn={key:0,class:"tools-list-wrapper"},Zn={class:"tools-list"},Qn=["onClick"],Yn={class:"tool-header"},Xn={class:"tool-checkbox"},es={class:"tool-info"},ts=["title"],os={class:"tooltip-description"},ns={class:"tool-actions"},ss={class:"detail-section"},rs=["onDblclick"],as={key:2,class:"description-actions"},ls={key:0,class:"detail-section"},is={class:"params-list"},cs={class:"param-header"},us={class:"param-name"},ds={key:0,class:"param-type"},ps={key:1,class:"param-required"},vs=["onDblclick"],gs={key:2,class:"field-description-actions"},ms={key:1,class:"detail-section"},fs={key:1,class:"tools-empty"},hs={key:2,class:"tools-error"},ys={class:"modal-footer"},ws={style:{"font-size":"12px",color:"#666"}},bs={key:0},ks={class:"modal-footer"},Cs=ht({__name:"MCPComponentsManager",props:{config:{}},emits:["update"],setup(t,{emit:a}){const s=t,c=a,u=Dt(),h=A(!1),j=A("config"),k=A("form"),$=A(!1),P=A(!1),R=A(!1),V=A(!1),D=A(""),L=A(null),Y=A(),H=A(""),z=A(""),U=A({}),C=A(!1),B=A({current:0,total:0,currentComponent:""});function le(i){j.value=i}const J=A([]),Z=A(new Set),_=A({}),ge=A(0),$e=Te(()=>{const i=l.value.toolPatches,e=_.value,n=J.value;ge.value;const w={};return n.forEach(g=>{var b;const f=he(g),S=i[f];S&&S.description!==void 0&&S.description!==null&&S.description!==""?w[g.name]=S.description:w[g.name]=((b=e[f])==null?void 0:b.description)||"暂无描述"}),w}),me=A(null),we=A(null),de=A(""),Be=A("tool"),Ce=A(""),Se=A(""),l=A({name:"",type:"npm",package:"",version:"",url:"",command:"",args:[],env:[],headers:[],disabledTools:[],toolPatches:{},namespace:"",extraConfig:{},rootExtra:{},configStr:"{}",disabled:!1}),K=[{label:"NPM 包",value:"npm"},{label:"Stdio (Command)",value:"stdio"},{label:"SSE (URL)",value:"url"}],ee={name:{required:!0,message:"请输入名称",trigger:"blur"},type:{required:!0,message:"请选择类型",trigger:"change"}};function Ne(i){const e={};return i.forEach(n=>{n.key&&(e[n.key]=n.value)}),e}function Pe(i){return i?Object.entries(i).map(([e,n])=>({key:e,value:n})):[]}function _e(i,e){const n=[...s.config.components],w=n.findIndex(g=>g.id===i.id);w!==-1&&(n[w]={...i,disabled:!e},c("update",{components:n}))}function Oe(i){var M,se,oe;const e=(M=i.config)!=null&&M.headers?Pe(i.config.headers):[],n=((se=i.config)==null?void 0:se.disabledTools)||[],w=(oe=i.config)!=null&&oe.toolPatches?JSON.parse(JSON.stringify(i.config.toolPatches)):{};console.log("加载时的 toolPatches:",JSON.stringify(w,null,2));const{headers:g,disabledTools:f,toolPatches:S,tools:x,...b}=i.config||{},te=["id","name","type","namespace","env","package","version","url","command","args","config","disabled"],N={};Object.keys(i).forEach(E=>{te.includes(E)||(N[E]=i[E])}),l.value={name:i.name||"",type:i.type||"npm",package:i.package||"",version:i.version||"",url:i.url||"",command:i.command||"",args:i.args||[],env:Pe(i.env),headers:e,disabledTools:n,toolPatches:w,namespace:i.namespace||"",extraConfig:b,rootExtra:N,configStr:JSON.stringify(i,null,2),disabled:!!i.disabled}}function ot(){const i={...l.value.rootExtra,name:l.value.name,type:l.value.type,namespace:l.value.namespace||void 0,env:l.value.env.length>0?Ne(l.value.env):void 0,disabled:l.value.disabled?!0:void 0};l.value.type==="npm"?(i.package=l.value.package,i.version=l.value.version||void 0):l.value.type==="url"?i.url=l.value.url:l.value.type==="stdio"&&(i.command=l.value.command,i.args=l.value.args);const e={...l.value.extraConfig};return e.disabledTools=l.value.disabledTools,l.value.headers.length>0&&(e.headers=Ne(l.value.headers)),J.value.length>0&&(e.tools=J.value),l.value.toolPatches&&Object.keys(l.value.toolPatches).length>0&&(e.toolPatches=JSON.parse(JSON.stringify(l.value.toolPatches))),Object.keys(e).length>0&&(i.config=e),JSON.parse(JSON.stringify(i))}ke(k,i=>{var e;if(j.value==="config"){if(i==="json")try{const n=ot();(e=L.value)!=null&&e.id&&(n.id=L.value.id),l.value.configStr=JSON.stringify(n,null,2)}catch(n){console.error(n)}else if(i==="form")try{const n=JSON.parse(l.value.configStr);Oe(n)}catch{u.error("JSON 格式错误,忽略更改")}}});async function O(i){var e;L.value=i,j.value="config",k.value="form",Oe(i),J.value=[],D.value="",Z.value.clear(),me.value=null,we.value=null,de.value="",_.value={},console.log("[editComponent] form.value.toolPatches after fillFormFromData:",JSON.stringify(l.value.toolPatches,null,2)),console.log("[editComponent] component.config?.toolPatches:",JSON.stringify((e=i.config)==null?void 0:e.toolPatches,null,2)),await He(i.id,!0),console.log("[editComponent] form.value.toolPatches after loadComponentTools:",JSON.stringify(l.value.toolPatches,null,2)),console.log("[editComponent] originalTools after loadComponentTools:",JSON.stringify(_.value,null,2)),h.value=!0}async function He(i,e=!1){var n,w,g,f,S,x,b,te;try{const N=await ue.get(`/configs/component-tools/${i}`);if(N.data.success&&N.data.data.tools&&N.data.data.tools.length>0){const M=s.config.components.find(T=>T.id===i),se=e?((n=M==null?void 0:M.config)==null?void 0:n.toolPatches)||{}:{},oe=Array.isArray((w=M==null?void 0:M.config)==null?void 0:w.disabledTools)?M.config.disabledTools:[],E={};J.value=N.data.data.tools.map(T=>{const X=T.originalToolName||T.name;if(T.originalDescription!==void 0&&T.originalInputSchema!==void 0)E[X]={description:T.originalDescription||"",inputSchema:JSON.parse(JSON.stringify(T.originalInputSchema||{type:"object",properties:{}}))};else{const ye=se[X];ye&&ye.description!==void 0&&ye.description!==null&&ye.description!==""?(console.warn(`[loadComponentTools] 无法获取工具 ${X} 的原始数据,因为后端 API 没有返回 originalDescription`),_.value[X]?E[X]=_.value[X]:E[X]={description:"",inputSchema:{type:"object",properties:{}}}):E[X]={description:T.description||"",inputSchema:JSON.parse(JSON.stringify(T.inputSchema||{type:"object",properties:{}}))}}let pe=T.inputSchema||{type:"object",properties:{}};if(e&&se[X]){const ye=se[X];ye.inputSchema&&(pe={...pe,...ye.inputSchema})}return{name:T.name,description:T.description||"",inputSchema:pe,disabled:oe.includes(X),originalToolName:X}}),e&&Object.keys(_.value).forEach(T=>{E[T]||(E[T]=_.value[T])}),Object.keys(E).forEach(T=>{var X;E[T].description===""&&((X=_.value[T])!=null&&X.description)&&(E[T]=_.value[T])}),_.value=E;const re=l.value.toolPatches&&Object.keys(l.value.toolPatches).length>0?l.value.toolPatches:((g=M==null?void 0:M.config)==null?void 0:g.toolPatches)||{};console.log("[loadComponentTools] existingToolPatches:",JSON.stringify(re,null,2)),console.log("[loadComponentTools] form.value.toolPatches:",JSON.stringify(l.value.toolPatches,null,2)),console.log("[loadComponentTools] component.config?.toolPatches:",JSON.stringify((f=M==null?void 0:M.config)==null?void 0:f.toolPatches,null,2));const W={},ae=new Set(J.value.map(T=>T.originalToolName||T.name).filter(T=>T!=null&&T!==""));console.log("[loadComponentTools] currentToolNames:",Array.from(ae)),console.log("[loadComponentTools] existingToolPatches keys:",Object.keys(re)),Object.keys(re).forEach(T=>{ae.has(T)?(W[T]=re[T],console.log(`[loadComponentTools] 保留 toolPatch: ${T}`)):console.log(`[loadComponentTools] 过滤掉 toolPatch: ${T} (不在当前工具列表中)`)}),M&&(e||Object.keys(W).length>0)&&(M.config?M.config.toolPatches=W:M.config={toolPatches:W}),l.value.toolPatches=JSON.parse(JSON.stringify(W)),console.log("[loadComponentTools] final form.value.toolPatches:",JSON.stringify(l.value.toolPatches,null,2)),console.log("[loadComponentTools] originalTools:",JSON.stringify(_.value,null,2));return}}catch(N){((S=N.response)==null?void 0:S.status)===404?console.log("数据库中没有工具列表,尝试从 MCP 组件加载"):console.warn("从数据库加载工具列表失败:",N)}try{const N=s.config.components.find(se=>se.id===i);if(!N){J.value=[];return}const M=await ue.post("/configs/component-tools/load",{componentId:i});if(M.data.success&&M.data.data.tools){const se=e?((x=N.config)==null?void 0:x.toolPatches)||{}:{},oe=Array.isArray((b=N.config)==null?void 0:b.disabledTools)?N.config.disabledTools:[],E={};J.value=M.data.data.tools.map(T=>{const X=T.originalToolName||(()=>{const ye=T.name.split("_");return ye.length>1?ye.slice(-1)[0]:T.name})();E[X]={description:T.description||"",inputSchema:JSON.parse(JSON.stringify(T.inputSchema||{type:"object",properties:{}}))};let pe=T.inputSchema||{type:"object",properties:{}};if(e&&se[X]){const ye=se[X];ye.inputSchema&&(pe={...pe,...ye.inputSchema})}return{name:T.name,description:T.description||"",inputSchema:pe,disabled:oe.includes(X),originalToolName:X}}),e&&Object.keys(_.value).forEach(T=>{E[T]||(E[T]=_.value[T])}),_.value=E;const re=l.value.toolPatches&&Object.keys(l.value.toolPatches).length>0?l.value.toolPatches:((te=N.config)==null?void 0:te.toolPatches)||{};console.log("[loadComponentTools-from-MCP] existingToolPatches:",JSON.stringify(re,null,2));const W={},ae=new Set(J.value.map(T=>T.originalToolName));Object.keys(re).forEach(T=>{ae.has(T)&&(W[T]=re[T])}),e&&N&&(N.config?N.config.toolPatches=W:N.config={toolPatches:W}),l.value.toolPatches=JSON.parse(JSON.stringify(W)),console.log("[loadComponentTools-from-MCP] final form.value.toolPatches:",JSON.stringify(l.value.toolPatches,null,2)),console.log("[loadComponentTools-from-MCP] originalTools:",JSON.stringify(_.value,null,2))}else J.value=[]}catch(N){console.warn("从 MCP 组件加载工具列表失败:",N),J.value=[]}}function wt(i){const e=s.config.components.filter(n=>n.id!==i);c("update",{components:e})}async function bt(i){var e,n,w;U.value[i.id]=!0;try{const g=await ue.post("/configs/sync-tools",{componentId:i.id});if(g.data.success)if(g.data.data.errors&&g.data.data.errors.length>0)u.error(`同步工具失败: ${g.data.data.errors.join("; ")}`);else if(g.data.data.success>0){u.success(`工具同步成功:${g.data.data.success} 个工具已更新`),g.data.data.failed>0&&u.warning(`${g.data.data.failed} 个工具同步失败`);try{const f=await ue.get(`/configs/component-tools/${i.id}`);if(f.data.success&&f.data.data.tools){const S=f.data.data.tools.length,x=[...s.config.components],b=x.findIndex(te=>te.id===i.id);b!==-1&&(x[b]={...x[b],config:{...x[b].config,toolCount:S}},c("update",{components:x}))}}catch(f){console.warn("更新组件工具总数失败:",f)}((e=L.value)==null?void 0:e.id)===i.id&&await He(i.id,!0)}else u.warning("没有工具需要同步");else u.error(`同步工具失败: ${g.data.error||"未知错误"}`)}catch(g){u.error(`同步工具失败: ${((w=(n=g.response)==null?void 0:n.data)==null?void 0:w.error)||g.message}`)}finally{U.value[i.id]=!1}}async function nt(){var i,e;if(!L.value){u.warning("请先选择要编辑的组件");return}V.value=!0,D.value="";try{const n=await ue.post("/configs/sync-tools",{componentId:L.value.id});n.data.success?n.data.data.errors&&n.data.data.errors.length>0?(D.value=n.data.data.errors.join("; "),u.error(`同步工具失败: ${D.value}`)):n.data.data.success>0?(u.success(`工具同步成功:${n.data.data.success} 个工具已更新`),n.data.data.failed>0&&(u.warning(`${n.data.data.failed} 个工具同步失败`),n.data.data.errors&&n.data.data.errors.length>0&&(D.value=n.data.data.errors.join("; "))),await He(L.value.id,!0)):u.warning("没有工具需要同步"):(D.value=n.data.error||"同步失败",u.error(`同步工具失败: ${D.value}`))}catch(n){D.value=((e=(i=n.response)==null?void 0:i.data)==null?void 0:e.error)||n.message,u.error(`同步工具失败: ${D.value}`)}finally{V.value=!1}}function st(i){var n,w,g;const e=((n=i.config)==null?void 0:n.toolCount)??((g=(w=i.config)==null?void 0:w.tools)==null?void 0:g.length);return e!=null&&e>0?e:null}function rt(i){var w,g,f,S,x;const e=((w=i.config)==null?void 0:w.toolCount)??((f=(g=i.config)==null?void 0:g.tools)==null?void 0:f.length),n=((x=(S=i.config)==null?void 0:S.disabledTools)==null?void 0:x.length)||0;if(e!=null&&e>0){const b=Math.max(0,e-n);return b>0?b:null}return null}function kt(i){const e=i.originalToolName||i.name;return l.value.disabledTools.includes(e)}function Ct(i,e){const n=i.originalToolName||i.name;e?l.value.disabledTools=l.value.disabledTools.filter(w=>w!==n):l.value.disabledTools.includes(n)||l.value.disabledTools.push(n)}function Ke(){l.value.disabledTools=[],u.success("已全选所有工具")}function xt(){const i=J.value.map(n=>n.originalToolName||n.name),e=new Set(l.value.disabledTools);l.value.disabledTools=i.filter(n=>!e.has(n)),u.success("已反选工具")}function he(i){return i.originalToolName||i.name}function Je(i){return $e.value[i.name]||"暂无描述"}function at(i,e,n){var N,M,se,oe;ge.value;const w=he(i),g=l.value.toolPatches,f=_.value,S=g[w],x=f[w],b=(N=S==null?void 0:S.fieldDescriptions)==null?void 0:N[e];return b!=null&&b!==""?b:((oe=(se=(M=x==null?void 0:x.inputSchema)==null?void 0:M.properties)==null?void 0:se[e])==null?void 0:oe.description)||"暂无描述"}function lt(i){var f;const e=he(i),n=l.value.toolPatches[e],w=n==null?void 0:n.description;if(w==null||w==="")return!1;const g=((f=_.value[e])==null?void 0:f.description)||i.description||"暂无描述";return console.log(`[hasCustomDescription] Tool ${e}:`,{hasCustomDescription:!!w,customDescription:w==null?void 0:w.trim(),originalDescription:g==null?void 0:g.trim(),areDifferent:(w==null?void 0:w.trim())!==(g==null?void 0:g.trim()),toolPatches:l.value.toolPatches[e],originalTools:_.value[e],formToolPatches:l.value.toolPatches,allOriginalTools:_.value,toolKey:e,toolName:i.name,toolOriginalToolName:i.originalToolName}),!_.value[e]&&w?(console.log(`[hasCustomDescription] Tool ${e}: originalTools not loaded yet, but has custom description, returning true`),!0):(console.log(`[hasCustomDescription] Tool ${e}: toolPatches 中有描述,返回 true 以显示还原按钮`),!0)}function it(i,e){var S,x,b,te,N,M,se,oe,E,re,W,ae,T;const n=he(i),w=l.value.toolPatches[n],g=(S=w==null?void 0:w.fieldDescriptions)==null?void 0:S[e];if(g==null||g==="")return!1;const f=((N=(te=(b=(x=_.value[n])==null?void 0:x.inputSchema)==null?void 0:b.properties)==null?void 0:te[e])==null?void 0:N.description)||((oe=(se=(M=i.inputSchema)==null?void 0:M.properties)==null?void 0:se[e])==null?void 0:oe.description)||"暂无描述";return console.log(`[hasCustomFieldDescription] Tool ${n}, Field ${e}:`,{hasCustomDescription:!!g,customDescription:g==null?void 0:g.trim(),originalDescription:f==null?void 0:f.trim(),areDifferent:(g==null?void 0:g.trim())!==(f==null?void 0:f.trim()),fieldPatches:(E=w==null?void 0:w.fieldDescriptions)==null?void 0:E[e],originalFieldDesc:(T=(ae=(W=(re=_.value[n])==null?void 0:re.inputSchema)==null?void 0:W.properties)==null?void 0:ae[e])==null?void 0:T.description,hasOriginalTool:!!_.value[n],toolKey:n,toolName:i.name,toolOriginalToolName:i.originalToolName}),!_.value[n]&&g?(console.log(`[hasCustomFieldDescription] Tool ${n}, Field ${e}: originalTools not loaded yet, but has custom description, returning true`),!0):(console.log(`[hasCustomFieldDescription] Tool ${n}, Field ${e}: toolPatches 中有字段描述,返回 true 以显示还原按钮`),!0)}function Ge(i,e,n,w){var g,f,S,x,b,te;if(e==="tool"){me.value=i,we.value=null;const N=J.value.find(M=>M.name===i);de.value=Je(N),Be.value="tool",Ce.value=he(N)}else{we.value=i,me.value=null;const N=J.value.find(M=>M.name===n);if(N&&((f=(g=N.inputSchema)==null?void 0:g.properties)!=null&&f[w])){const M=N?he(N):"";(te=(b=(x=(S=_.value[M])==null?void 0:S.inputSchema)==null?void 0:x.properties)==null?void 0:b[w])!=null&&te.description||N.inputSchema.properties[w].description,de.value=at(N,w)}else de.value="";Be.value="field",Ce.value=N?he(N):n||"",Se.value=w||""}}function Ie(i,e,n,w){var g,f,S,x,b,te,N,M,se;if(e==="tool"){const oe=J.value.find(ae=>ae.name===i),E=oe?he(oe):i,re=((g=_.value[E])==null?void 0:g.description)||(oe==null?void 0:oe.description)||"暂无描述",W=de.value.trim();W===re.trim()||W===""?l.value.toolPatches[E]&&(delete l.value.toolPatches[E].description,Object.keys(l.value.toolPatches[E]).length===0&&delete l.value.toolPatches[E]):(l.value.toolPatches[E]||(l.value.toolPatches[E]={}),l.value.toolPatches[E].description=W),me.value=null,u.success("工具描述已保存")}else{const oe=J.value.find(T=>T.name===n),E=oe?he(oe):n||Ce.value,re=w||Se.value,W=((b=(x=(S=(f=_.value[E])==null?void 0:f.inputSchema)==null?void 0:S.properties)==null?void 0:x[re])==null?void 0:b.description)||((M=(N=(te=oe==null?void 0:oe.inputSchema)==null?void 0:te.properties)==null?void 0:N[re])==null?void 0:M.description)||"暂无描述",ae=de.value.trim();ae===W.trim()||ae===""?(se=l.value.toolPatches[E])!=null&&se.fieldDescriptions&&(delete l.value.toolPatches[E].fieldDescriptions[re],Object.keys(l.value.toolPatches[E].fieldDescriptions).length===0&&delete l.value.toolPatches[E].fieldDescriptions,Object.keys(l.value.toolPatches[E]).length===0&&delete l.value.toolPatches[E]):(l.value.toolPatches[E]||(l.value.toolPatches[E]={}),l.value.toolPatches[E].fieldDescriptions||(l.value.toolPatches[E].fieldDescriptions={}),l.value.toolPatches[E].fieldDescriptions[re]=ae),we.value=null,u.success("字段描述已保存")}de.value="",Ce.value="",Se.value="",l.value.toolPatches=JSON.parse(JSON.stringify(l.value.toolPatches)),ge.value++,console.log("保存描述后的 toolPatches:",JSON.stringify(l.value.toolPatches,null,2)),Fe(()=>{console.log("保存描述后 DOM 更新完成")})}function We(){me.value=null,we.value=null,de.value="",Ce.value="",Se.value=""}async function v(i,e,n,w){var g,f,S,x,b,te,N,M,se,oe,E;if(e==="tool"){const re=J.value.find(ae=>ae.name===i),W=re?he(re):i;if(l.value.toolPatches[W]){const ae=l.value.toolPatches,T={};Object.keys(ae).forEach(X=>{if(X!==W)T[X]={...ae[X]};else{const pe={...ae[X]};delete pe.description,Object.keys(pe).length>0&&(T[X]=pe)}}),l.value.toolPatches=T,ge.value++,console.log("[resetDescription-tool] 还原后的 toolPatches:",JSON.stringify(l.value.toolPatches,null,2)),console.log("[resetDescription-tool] toolKey:",W),console.log("[resetDescription-tool] 还原后的 patch:",l.value.toolPatches[W]),console.log("[resetDescription-tool] originalTools:",JSON.stringify(_.value[W],null,2)),console.log("[resetDescription-tool] toolDescriptionsMap 值:",$e.value[re.name]),u.success("工具描述已还原")}}else{const re=J.value.find(T=>T.name===n),W=re?he(re):n||Ce.value,ae=w||Se.value;if((g=l.value.toolPatches[W])!=null&&g.fieldDescriptions){const T=l.value.toolPatches,X={};Object.keys(T).forEach(Ze=>{if(Ze!==W)X[Ze]={...T[Ze]};else{const Ee={...T[Ze]};if(Ee.fieldDescriptions){const Tt={};Object.keys(Ee.fieldDescriptions).forEach(St=>{St!==ae&&(Tt[St]=Ee.fieldDescriptions[St])}),Object.keys(Tt).length>0?Ee.fieldDescriptions=Tt:delete Ee.fieldDescriptions}Object.keys(Ee).length>0&&(X[Ze]=Ee)}}),l.value.toolPatches=JSON.parse(JSON.stringify(X)),ge.value++,console.log("[resetDescription-field] 还原后的 toolPatches:",JSON.stringify(l.value.toolPatches,null,2)),console.log("[resetDescription-field] actualToolKey:",W),console.log("[resetDescription-field] actualFieldName:",ae),console.log("[resetDescription-field] 还原后的 patch:",l.value.toolPatches[W]),console.log("[resetDescription-field] 还原后的 patch.fieldDescriptions:",(f=l.value.toolPatches[W])==null?void 0:f.fieldDescriptions),console.log("[resetDescription-field] originalTools:",JSON.stringify(_.value[W],null,2)),console.log("[resetDescription-field] originalTools 字段描述:",(te=(b=(x=(S=_.value[W])==null?void 0:S.inputSchema)==null?void 0:x.properties)==null?void 0:b[ae])==null?void 0:te.description),await Fe();const pe=l.value.toolPatches[W],ye=(N=pe==null?void 0:pe.fieldDescriptions)==null?void 0:N[ae],lo=((E=(oe=(se=(M=_.value[W])==null?void 0:M.inputSchema)==null?void 0:se.properties)==null?void 0:oe[ae])==null?void 0:E.description)||"暂无描述";console.log("[resetDescription-field] 还原后的 patch.fieldDescriptions:",pe==null?void 0:pe.fieldDescriptions),console.log("[resetDescription-field] 字段描述是否已删除:",ye===void 0),console.log("[resetDescription-field] 期望的原始值:",lo),ge.value++,await Fe(),u.success("字段描述已还原")}}de.value="",Ce.value="",Se.value="",console.log("还原描述后的 toolPatches:",JSON.stringify(l.value.toolPatches,null,2)),console.log("还原描述后的 originalTools:",JSON.stringify(_.value,null,2)),Fe(()=>{console.log("DOM 更新完成,descriptionUpdateKey:",ge.value)})}function r(i){Z.value.has(i)?Z.value.delete(i):(Z.value.clear(),Z.value.add(i))}async function y(){var i,e,n,w;try{if(j.value==="config"&&k.value==="json")try{const x=JSON.parse(l.value.configStr||"{}");Oe(x)}catch{throw new Error("配置 JSON 格式错误")}if(await((i=Y.value)==null?void 0:i.validate()),P.value=!0,J.value.length===0)try{const x={id:((e=L.value)==null?void 0:e.id)||Qe(),name:l.value.name,type:l.value.type,namespace:l.value.namespace,env:Ne(l.value.env),config:{headers:Ne(l.value.headers)}};l.value.type==="npm"?(x.package=l.value.package,x.version=l.value.version):l.value.type==="url"?x.url=l.value.url:l.value.type==="stdio"&&(x.command=l.value.command,x.args=l.value.args);const b=await ue.post("/mcp/inspect",x);J.value=b.data.data.tools||[],J.value.length>0&&u.info(`自动获取到 ${J.value.length} 个工具`)}catch(x){console.warn("自动获取工具列表失败:",x)}console.log("保存前的 toolPatches:",JSON.stringify(l.value.toolPatches,null,2));const g=ot();g.id=((n=L.value)==null?void 0:n.id)||Qe(),console.log("保存的组件配置:",JSON.stringify(g,null,2)),console.log("组件 config.toolPatches:",JSON.stringify((w=g.config)==null?void 0:w.toolPatches,null,2));const f=[...s.config.components],S=f.findIndex(x=>x.id===g.id);S!==-1?f[S]=g:f.push(g),c("update",{components:f}),h.value=!1,xe()}catch(g){console.error("保存错误:",g),u.error(g.message)}finally{P.value=!1}}async function Q(){var i,e;C.value=!0,B.value={current:0,total:0,currentComponent:""};try{let n=[],w=[];if(H.value.trim()){const f=JSON.parse(H.value).mcpServers||{};w=Object.entries(f),B.value.total=w.length;for(let S=0;S<w.length;S++){const[x,b]=w[S];B.value.current=S+1,B.value.currentComponent=x;const te=!!b.url,N={headers:b.headers,disabledTools:b.disabledTools,toolPatches:b.toolPatches};b.transportType&&(N.transportType=b.transportType),b.type&&(N.type=b.type);const M={id:Qe(),name:x,type:te?"url":"stdio",url:b.url,command:b.command,args:b.args||[],env:b.env,config:N};try{const se={...M,config:{headers:b.headers||{}}},E=(await ue.post("/mcp/inspect",se)).data.data.tools||[];E.length>0&&(N.tools=E,M.config=N,console.log(`[导入] 组件 ${x} 解析到 ${E.length} 个工具`))}catch(se){console.warn(`[导入] 组件 ${x} 获取工具列表失败:`,se)}n.push(M)}}else if(z.value.trim()){const g=JSON.parse(z.value),f=Array.isArray(g)?g:g.components;B.value.total=f.length;for(let S=0;S<f.length;S++){const x=f[S];B.value.current=S+1,B.value.currentComponent=x.name||`组件 ${S+1}`;const b={...x,id:Qe()};if(!((i=b.config)!=null&&i.tools)&&(b.url||b.command||b.package))try{const te={...b,config:{...b.config,headers:((e=b.config)==null?void 0:e.headers)||{}}},M=(await ue.post("/mcp/inspect",te)).data.data.tools||[];M.length>0&&(b.config||(b.config={}),b.config.tools=M,console.log(`[导入] 组件 ${b.name} 解析到 ${M.length} 个工具`))}catch(te){console.warn(`[导入] 组件 ${b.name} 获取工具列表失败:`,te)}n.push(b)}}else throw new Error("请输入 JSON 内容");if(c("update",{components:[...s.config.components,...n]}),await new Promise(g=>setTimeout(g,800)),n.length>0){B.value.total=n.length,B.value.current=0;let g=0,f=0;for(let S=0;S<n.length;S++){const x=n[S];B.value.current=S+1,B.value.currentComponent=`正在同步工具: ${x.name}`;try{const b=await ue.post("/configs/sync-tools",{componentId:x.id});b.data.success?b.data.data.errors&&b.data.data.errors.length>0?(f++,console.warn(`[导入] 组件 ${x.name} 同步工具失败:`,b.data.data.errors.join("; "))):b.data.data.success>0&&(g++,console.log(`[导入] 组件 ${x.name} 同步了 ${b.data.data.success} 个工具`)):(f++,console.warn(`[导入] 组件 ${x.name} 同步工具失败:`,b.data.error))}catch(b){f++,console.warn(`[导入] 组件 ${x.name} 同步工具失败:`,b.message||b)}}g>0?u.success(`导入成功:${n.length} 个组件已添加,${g} 个组件的工具已同步`):f>0?u.warning(`导入完成:${n.length} 个组件已添加,但工具同步失败`):u.success(`导入成功:${n.length} 个组件已添加`)}$.value=!1,H.value="",z.value=""}catch(n){u.error(`导入失败: ${n.message}`)}finally{C.value=!1,B.value={current:0,total:0,currentComponent:""}}}function ie(){const i={};s.config.components.forEach(f=>{var x,b,te;const S={env:f.env};if(f.type==="url")S.url=f.url,(x=f.config)!=null&&x.headers&&(S.headers=f.config.headers);else{let N=f.command,M=f.args||[];f.type==="npm"&&(N="npx",M=["-y",f.package],f.version&&f.version!=="latest"&&(M[1]=`${f.package}@${f.version}`)),S.command=N,S.args=M}(b=f.config)!=null&&b.disabledTools&&(S.disabledTools=f.config.disabledTools),(te=f.config)!=null&&te.toolPatches&&(S.toolPatches=f.config.toolPatches),i[f.name]=S});const e=JSON.stringify({mcpServers:i},null,2),n=new Blob([e],{type:"application/json"}),w=URL.createObjectURL(n),g=document.createElement("a");g.href=w,g.download="cursor-mcp.json",g.click(),URL.revokeObjectURL(w),u.success("已导出 Cursor 格式配置")}function xe(){L.value=null,l.value={name:"",type:"npm",package:"",version:"",url:"",command:"",args:[],env:[],headers:[],disabledTools:[],toolPatches:{},namespace:"",extraConfig:{},rootExtra:{},configStr:"{}",disabled:!1},j.value="config",k.value="form",J.value=[],D.value="",me.value=null,we.value=null,de.value="",Ce.value="",Se.value=""}return ke(()=>h.value,i=>{i||xe()}),(i,e)=>(F(),q("div",gn,[t.config.components&&t.config.components.length>0?(F(),q("div",mn,[m(p(G),{type:"primary",size:"large",class:"add-component-btn",onClick:e[0]||(e[0]=n=>h.value=!0)},{icon:d(()=>[...e[28]||(e[28]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M12 4v16m8-8H4",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:d(()=>[e[29]||(e[29]=I(" 添加组件 ",-1))]),_:1}),o("div",fn,[m(p(G),{size:"large",class:"secondary-btn",onClick:e[1]||(e[1]=n=>$.value=!0)},{icon:d(()=>[...e[30]||(e[30]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:d(()=>[e[31]||(e[31]=I(" 导入 JSON ",-1))]),_:1}),m(p(G),{size:"large",class:"secondary-btn",onClick:ie},{icon:d(()=>[...e[32]||(e[32]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:d(()=>[e[33]||(e[33]=I(" 导出配置 ",-1))]),_:1})])])):ce("",!0),t.config.components&&t.config.components.length>0?(F(),q("div",hn,[m(p(uo),{class:"component-list","show-divider":!1},{default:d(()=>[(F(!0),q(dt,null,pt(t.config.components,n=>(F(),De(p(vo),{key:n.id},{default:d(()=>[o("div",yn,[o("div",wn,[o("div",bn,[o("div",kn,ne(n.name.charAt(0).toUpperCase()),1)]),o("div",Cn,[o("div",xn,[o("span",Tn,ne(n.name),1),n.namespace&&n.namespace.trim()!==""?(F(),De(p(Xe),{key:0,size:"small",type:"warning",style:{"margin-left":"8px"}},{default:d(()=>[I(" 命名空间:"+ne(n.namespace.trim()),1)]),_:2},1024)):ce("",!0),st(n)!==null?(F(),De(p(Xe),{key:1,size:"small",type:"info"},{default:d(()=>[I(ne(st(n))+" 工具 ",1)]),_:2},1024)):ce("",!0),rt(n)!==null?(F(),De(p(Xe),{key:2,size:"small",type:"success"},{default:d(()=>[I(ne(rt(n))+" 可调用 ",1)]),_:2},1024)):ce("",!0)])]),o("div",Sn,[m(p(po),{size:"small",value:!n.disabled,"onUpdate:value":w=>_e(n,w)},{checked:d(()=>[...e[34]||(e[34]=[I("启用",-1)])]),unchecked:d(()=>[...e[35]||(e[35]=[I("禁用",-1)])]),_:1},8,["value","onUpdate:value"]),m(p(G),{size:"small",loading:U.value[n.id],onClick:w=>bt(n),title:"同步工具配置"},{icon:d(()=>[...e[36]||(e[36]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M1 4v6h6M23 20v-6h-6M3.51 9a9 9 0 0114.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0020.49 15",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:d(()=>[e[37]||(e[37]=I(" 同步工具 ",-1))]),_:1},8,["loading","onClick"]),m(p(G),{size:"small",onClick:w=>O(n)},{default:d(()=>[...e[38]||(e[38]=[I("配置",-1)])]),_:1},8,["onClick"]),m(p(G),{size:"small",type:"error",ghost:"",onClick:w=>wt(n.id)},{default:d(()=>[...e[39]||(e[39]=[I("移除",-1)])]),_:1},8,["onClick"])])]),n.config?(F(),q("div",$n)):ce("",!0)])]),_:2},1024))),128))]),_:1})])):(F(),q("div",Pn,[o("div",jn,[e[44]||(e[44]=Wt('<div class="empty-icon" data-v-46d5bbd7><svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" data-v-46d5bbd7><path d="M12 2L2 7l10 5 10-5-10-5z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" data-v-46d5bbd7></path><path d="M2 17l10 5 10-5M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" data-v-46d5bbd7></path></svg></div><h3 class="empty-title" data-v-46d5bbd7>还没有添加 MCP 组件</h3><p class="empty-description" data-v-46d5bbd7>点击上方&quot;添加组件&quot;按钮开始添加你的第一个 MCP 组件,或者使用&quot;导入 JSON&quot;快速导入配置</p>',3)),o("div",Nn,[m(p(G),{type:"primary",size:"large",onClick:e[2]||(e[2]=n=>h.value=!0)},{icon:d(()=>[...e[40]||(e[40]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M12 4v16m8-8H4",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:d(()=>[e[41]||(e[41]=I(" 添加组件 ",-1))]),_:1}),m(p(G),{size:"large",onClick:e[3]||(e[3]=n=>$.value=!0)},{icon:d(()=>[...e[42]||(e[42]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:d(()=>[e[43]||(e[43]=I(" 导入 JSON ",-1))]),_:1})])])])),m(p(vt),{show:h.value,"onUpdate:show":e[24]||(e[24]=n=>h.value=n),preset:"card",bordered:!1,class:"component-edit-modal",style:{width:"90vw",maxWidth:"1400px",height:"90vh",maxHeight:"90vh"}},{header:d(()=>[o("div",On,[e[45]||(e[45]=o("div",{class:"modal-icon"},[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1",stroke:"currentColor","stroke-width":"2"}),o("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1",stroke:"currentColor","stroke-width":"2"}),o("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1",stroke:"currentColor","stroke-width":"2"}),o("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1",stroke:"currentColor","stroke-width":"2"})])],-1)),o("div",null,[o("h3",Mn,ne(L.value?"配置 MCP 组件":"添加 MCP 组件"),1),o("p",An,ne(L.value?"修改组件配置和工具设置":"创建新的 MCP 服务组件"),1)])])]),footer:d(()=>[o("div",ys,[m(p(G),{size:"large",onClick:e[23]||(e[23]=n=>h.value=!1)},{default:d(()=>[...e[72]||(e[72]=[I("取消",-1)])]),_:1}),m(p(G),{type:"primary",size:"large",onClick:y},{default:d(()=>[I(ne(L.value?"保存修改":"添加组件"),1)]),_:1})])]),default:d(()=>[o("div",Dn,[m(p(Zt),{value:j.value,"onUpdate:value":[e[22]||(e[22]=n=>j.value=n),le],type:"line",animated:"",size:"large",class:"component-config-tabs"},{default:d(()=>[m(p(gt),{name:"config",tab:"基础配置"},{default:d(()=>[o("div",zn,[o("div",_n,[m(p(go),{value:k.value,"onUpdate:value":e[4]||(e[4]=n=>k.value=n),size:"medium"},{default:d(()=>[m(p(Ft),{value:"form"},{default:d(()=>[...e[46]||(e[46]=[o("div",{class:"radio-btn-content"},[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})]),o("span",null,"表单模式")],-1)])]),_:1}),m(p(Ft),{value:"json"},{default:d(()=>[...e[47]||(e[47]=[o("div",{class:"radio-btn-content"},[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("polyline",{points:"16 18 22 12 16 6",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"}),o("polyline",{points:"8 6 2 12 8 18",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})]),o("span",null,"JSON 模式")],-1)])]),_:1})]),_:1},8,["value"])]),Et(o("div",En,[m(p(Qt),{ref_key:"formRef",ref:Y,model:l.value,rules:ee,"label-placement":"top",size:"large"},{default:d(()=>[o("div",Fn,[e[51]||(e[51]=o("h4",{class:"section-title"},"基础信息",-1)),o("div",Un,[m(p(fe),{path:"name"},{label:d(()=>[...e[48]||(e[48]=[o("div",{class:"form-label"},[o("svg",{class:"label-icon",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})]),o("span",null,"组件名称")],-1)])]),default:d(()=>[m(p(be),{value:l.value.name,"onUpdate:value":e[5]||(e[5]=n=>l.value.name=n),placeholder:"例如: filesystem, github"},null,8,["value"])]),_:1}),m(p(fe),{path:"type"},{label:d(()=>[...e[49]||(e[49]=[o("div",{class:"form-label"},[o("svg",{class:"label-icon",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M7 21a4 4 0 01-4-4V5a2 2 0 012-2h4a2 2 0 012 2v12a4 4 0 01-4 4zm0 0h12a2 2 0 002-2v-4a2 2 0 00-2-2h-2.343M11 7.343l1.657-1.657a2 2 0 012.828 0l2.829 2.829a2 2 0 010 2.828l-8.486 8.485M7 17h.01",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})]),o("span",null,"组件类型")],-1)])]),default:d(()=>[m(p(Yt),{value:l.value.type,"onUpdate:value":e[6]||(e[6]=n=>l.value.type=n),options:K},null,8,["value"])]),_:1}),m(p(fe),{path:"namespace"},{label:d(()=>[...e[50]||(e[50]=[o("div",{class:"form-label"},[o("svg",{class:"label-icon",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})]),o("span",null,"命名空间(可选)")],-1)])]),default:d(()=>[m(p(be),{value:l.value.namespace,"onUpdate:value":e[7]||(e[7]=n=>l.value.namespace=n),placeholder:"用于工具名前缀"},null,8,["value"])]),_:1})])]),l.value.type==="npm"?(F(),q("div",Bn,[e[52]||(e[52]=o("h4",{class:"section-title"},"NPM 配置",-1)),o("div",Jn,[m(p(fe),{path:"package",label:"NPM 包名",class:"col-span-2"},{default:d(()=>[m(p(be),{value:l.value.package,"onUpdate:value":e[8]||(e[8]=n=>l.value.package=n),placeholder:"@modelcontextprotocol/server-filesystem"},null,8,["value"])]),_:1}),m(p(fe),{path:"version",label:"版本"},{default:d(()=>[m(p(be),{value:l.value.version,"onUpdate:value":e[9]||(e[9]=n=>l.value.version=n),placeholder:"latest"},null,8,["value"])]),_:1})])])):ce("",!0),l.value.type==="url"?(F(),q("div",In,[e[53]||(e[53]=o("h4",{class:"section-title"},"URL 配置",-1)),m(p(fe),{path:"url",label:"服务地址"},{default:d(()=>[m(p(be),{value:l.value.url,"onUpdate:value":e[10]||(e[10]=n=>l.value.url=n),placeholder:"http://localhost:3000/mcp"},null,8,["value"])]),_:1}),m(p(fe),{label:"HTTP Headers"},{default:d(()=>[m(p($t),{value:l.value.headers,"onUpdate:value":e[11]||(e[11]=n=>l.value.headers=n),preset:"pair","key-placeholder":"Header 名称","value-placeholder":"Header 值"},null,8,["value"])]),_:1})])):ce("",!0),l.value.type==="stdio"?(F(),q("div",Rn,[e[54]||(e[54]=o("h4",{class:"section-title"},"Stdio 配置",-1)),m(p(fe),{path:"command",label:"执行命令"},{default:d(()=>[m(p(be),{value:l.value.command,"onUpdate:value":e[12]||(e[12]=n=>l.value.command=n),placeholder:"node, python, uvx"},null,8,["value"])]),_:1}),m(p(fe),{label:"命令行参数"},{default:d(()=>[m(p($t),{value:l.value.args,"onUpdate:value":e[13]||(e[13]=n=>l.value.args=n),placeholder:"输入参数",min:0},null,8,["value"])]),_:1}),m(p(fe),{label:"环境变量"},{default:d(()=>[m(p($t),{value:l.value.env,"onUpdate:value":e[14]||(e[14]=n=>l.value.env=n),preset:"pair","key-placeholder":"变量名","value-placeholder":"变量值"},null,8,["value"])]),_:1})])):ce("",!0)]),_:1},8,["model"])],512),[[Ut,k.value==="form"]]),Et(o("div",Vn,[m(p(Le),{type:"info",bordered:!1,class:"json-alert"},{icon:d(()=>[...e[55]||(e[55]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:d(()=>[e[56]||(e[56]=I(" 直接编辑组件的完整 JSON 配置,切换回表单模式或保存时会自动同步 ",-1))]),_:1}),o("div",Ln,[m(ft,{modelValue:l.value.configStr,"onUpdate:modelValue":e[15]||(e[15]=n=>l.value.configStr=n),language:"json",options:{minimap:{enabled:!1},fontSize:14,lineHeight:22,padding:{top:16,bottom:16},automaticLayout:!0},style:{"min-height":"400px","border-radius":"12px",overflow:"hidden"}},null,8,["modelValue"])])],512),[[Ut,k.value==="json"]])])]),_:1}),m(p(gt),{name:"tools",tab:"工具管理"},{default:d(()=>[o("div",qn,[o("div",Hn,[m(p(Le),{type:"info",bordered:!1,class:"tools-info-alert"},{icon:d(()=>[...e[57]||(e[57]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:d(()=>[e[58]||(e[58]=I(' 工具列表来自已保存的配置。您可以禁用特定工具或编辑其 Schema。点击"同步工具"可从 MCP 组件更新工具列表。双击工具描述或字段描述可进行编辑。 ',-1))]),_:1}),o("div",Kn,[m(p(G),{type:"primary",size:"large",loading:V.value,onClick:nt,class:"sync-btn"},{icon:d(()=>[...e[59]||(e[59]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M1 4v6h6M23 20v-6h-6M3.51 9a9 9 0 0114.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0020.49 15",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:d(()=>[I(" "+ne(V.value?"同步中...":"同步工具配置"),1)]),_:1},8,["loading"]),J.value.length>0?(F(),q("div",Gn,[m(p(G),{size:"medium",onClick:Ke,class:"batch-btn"},{default:d(()=>[...e[60]||(e[60]=[I(" 全选 ",-1)])]),_:1}),m(p(G),{size:"medium",onClick:xt,class:"batch-btn"},{default:d(()=>[...e[61]||(e[61]=[I(" 反选 ",-1)])]),_:1})])):ce("",!0)])]),J.value.length>0?(F(),q("div",Wn,[o("div",Zn,[(F(!0),q(dt,null,pt(J.value,n=>(F(),q("div",{key:n.name,class:Ae(["tool-card",{"tool-expanded":Z.value.has(n.name)}]),onClick:w=>r(n.name)},[o("div",Yn,[o("div",Xn,[m(p(Xt),{checked:!kt(n),onClick:e[16]||(e[16]=je(()=>{},["stop"])),"onUpdate:checked":w=>Ct(n,w),size:"large"},null,8,["checked","onUpdate:checked"])]),o("div",es,[m(p(mo),{trigger:"hover","show-arrow":!0,placement:"top"},{trigger:d(()=>[o("h5",{class:"tool-name",title:Je(n)},ne(n.originalToolName||n.name),9,ts)]),default:d(()=>[o("div",os,ne(Je(n)),1)]),_:2},1024)]),o("div",ns,[o("div",{class:Ae(["expand-icon",{expanded:Z.value.has(n.name)}])},[...e[62]||(e[62]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("polyline",{points:"6 9 12 15 18 9",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])],2)])]),m(p(fo),{show:Z.value.has(n.name)},{default:d(()=>{var w;return[o("div",{class:"tool-details",onClick:e[21]||(e[21]=je(()=>{},["stop"]))},[o("div",ss,[o("div",{class:Ae(["detail-content",{"has-custom-description":lt(n)}])},[me.value!==n.name?(F(),q("div",{onDblclick:je(g=>Ge(n.name,"tool"),["stop"]),class:"description-text-editable",key:`tool-desc-${n.name}-${ge.value}`},ne(Je(n)),41,rs)):(F(),De(p(be),{key:1,value:de.value,"onUpdate:value":e[17]||(e[17]=g=>de.value=g),type:"textarea",rows:3,onBlur:g=>Ie(n.name,"tool"),onKeydown:[ct(je(g=>Ie(n.name,"tool"),["ctrl"]),["enter"]),ct(We,["esc"])],class:"description-input",placeholder:"输入工具描述",onClick:e[18]||(e[18]=je(()=>{},["stop"]))},null,8,["value","onBlur","onKeydown"])),lt(n)&&me.value!==n.name?(F(),q("div",as,[e[64]||(e[64]=o("span",{class:"custom-badge",title:"已自定义描述"},"已修改",-1)),m(p(G),{text:"",size:"small",onClick:je(g=>v(n.name,"tool"),["stop"]),class:"reset-btn"},{default:d(()=>[...e[63]||(e[63]=[I(" 还原 ",-1)])]),_:1},8,["onClick"])])):ce("",!0)],2)]),(w=n.inputSchema)!=null&&w.properties&&Object.keys(n.inputSchema.properties).length>0?(F(),q("div",ls,[e[67]||(e[67]=o("div",{class:"detail-section-header"},[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1",stroke:"currentColor","stroke-width":"2"}),o("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1",stroke:"currentColor","stroke-width":"2"}),o("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1",stroke:"currentColor","stroke-width":"2"}),o("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1",stroke:"currentColor","stroke-width":"2"})]),o("h6",null,"参数 Schema")],-1)),o("div",is,[(F(!0),q(dt,null,pt(n.inputSchema.properties,(g,f)=>{var S;return F(),q("div",{key:String(f),class:"param-item"},[o("div",cs,[o("span",us,ne(f),1),g.type?(F(),q("span",ds,ne(g.type),1)):ce("",!0),(S=n.inputSchema.required)!=null&&S.includes(String(f))?(F(),q("span",ps,"必填")):ce("",!0)]),o("div",{class:Ae(["param-description-wrapper",{"has-custom-description":it(n,String(f))}])},[we.value!==`${n.name}.${String(f)}`?(F(),q("div",{class:"param-description",onDblclick:je(x=>Ge(`${n.name}.${String(f)}`,"field",n.name,String(f)),["stop"]),key:`field-desc-${n.name}-${String(f)}-${ge.value}`},ne(at(n,String(f),g.description)),41,vs)):(F(),De(p(be),{key:1,value:de.value,"onUpdate:value":e[19]||(e[19]=x=>de.value=x),type:"textarea",rows:2,onBlur:x=>Ie(`${n.name}.${String(f)}`,"field",n.name,String(f)),onKeydown:[ct(je(x=>Ie(`${n.name}.${String(f)}`,"field",n.name,String(f)),["ctrl"]),["enter"]),ct(We,["esc"])],class:"description-input",placeholder:"输入字段描述",onClick:e[20]||(e[20]=je(()=>{},["stop"]))},null,8,["value","onBlur","onKeydown"])),it(n,String(f))&&we.value!==`${n.name}.${String(f)}`?(F(),q("div",gs,[e[66]||(e[66]=o("span",{class:"custom-badge",title:"已自定义描述"},"已修改",-1)),m(p(G),{text:"",size:"small",onClick:je(x=>v(`${n.name}.${String(f)}`,"field",n.name,String(f)),["stop"]),class:"reset-btn"},{default:d(()=>[...e[65]||(e[65]=[I(" 还原 ",-1)])]),_:1},8,["onClick"])])):ce("",!0)],2)])}),128))])])):(F(),q("div",ms,[...e[68]||(e[68]=[o("div",{class:"empty-params"},[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"2"}),o("path",{d:"M12 16v-4m0-4h.01",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round"})]),o("p",null,"该工具没有输入参数")],-1)])]))])]}),_:2},1032,["show"])],10,Qn))),128))])])):R.value?ce("",!0):(F(),q("div",fs,[...e[69]||(e[69]=[o("div",{class:"empty-content"},[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})]),o("h4",null,"暂无工具列表"),o("p",null,'点击上方"同步工具配置"按钮从 MCP 组件获取工具列表')],-1)])])),D.value?(F(),q("div",hs,[m(p(Le),{type:"error",bordered:!1},{icon:d(()=>[...e[70]||(e[70]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),header:d(()=>[...e[71]||(e[71]=[I("连接失败",-1)])]),default:d(()=>[I(" "+ne(D.value),1)]),_:1})])):ce("",!0)])]),_:1})]),_:1},8,["value"])])]),_:1},8,["show"]),m(p(vt),{show:$.value,"onUpdate:show":e[27]||(e[27]=n=>$.value=n),preset:"card",title:"导入组件 JSON",bordered:!1,class:"import-modal",style:{width:"800px",maxWidth:"90vw"}},{footer:d(()=>[o("div",ks,[m(p(G),{size:"large",onClick:e[26]||(e[26]=n=>$.value=!1),disabled:C.value},{default:d(()=>[...e[76]||(e[76]=[I("取消",-1)])]),_:1},8,["disabled"]),m(p(G),{type:"primary",size:"large",onClick:Q,loading:C.value},{default:d(()=>[I(ne(C.value?`导入中... (${B.value.current}/${B.value.total})`:"导入"),1)]),_:1},8,["loading"])])]),default:d(()=>[m(p(Le),{type:"info",bordered:!1,style:{"margin-bottom":"20px"}},{icon:d(()=>[...e[73]||(e[73]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:d(()=>[e[74]||(e[74]=I(" 粘贴 Cursor MCP 配置的 JSON(mcpServers 对象) ",-1))]),_:1}),C.value?(F(),De(p(Le),{key:0,type:"info",bordered:!1,style:{"margin-bottom":"20px"}},{icon:d(()=>[m(p(yo),{size:"small"})]),default:d(()=>[o("div",null,[e[75]||(e[75]=o("div",{style:{"margin-bottom":"8px"}},[o("strong",null,"正在导入组件...")],-1)),o("div",ws,[I(ne(B.value.currentComponent)+" ",1),B.value.total>0?(F(),q("span",bs," ("+ne(B.value.current)+"/"+ne(B.value.total)+") ",1)):ce("",!0)]),B.value.total>0?(F(),De(p(ho),{key:0,percentage:Math.round(B.value.current/B.value.total*100),"show-indicator":!1,style:{"margin-top":"8px"}},null,8,["percentage"])):ce("",!0)])]),_:1})):ce("",!0),m(ft,{modelValue:H.value,"onUpdate:modelValue":e[25]||(e[25]=n=>H.value=n),language:"json",options:{minimap:{enabled:!1},fontSize:14,lineHeight:22,padding:{top:16,bottom:16}},style:{height:"400px","border-radius":"12px",overflow:"hidden"}},null,8,["modelValue"])]),_:1},8,["show"])]))}}),Tr=zt(Cs,[["__scopeId","data-v-46d5bbd7"]]);function Ue(t){return!t||typeof t!="string"?"Unknown":t.split(/[^a-zA-Z0-9_$]+/).filter(s=>s.length>0).map(s=>s.split("_").filter(c=>c.length>0).map(c=>c.charAt(0).toUpperCase()+c.slice(1).toLowerCase()).join("")).join("")||"Unknown"}function Gt(t){return Ue(t)}function Me(t){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(t)?`"${t}"`:`"${t.replace(/"/g,'\\"')}"`}function _t(t){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(t)?t:`"${t.replace(/"/g,'\\"')}"`}function qe(t,a="",s=0){if(s>10)return console.warn("JSON Schema conversion reached maximum depth, returning any"),"any";if(!t||typeof t!="object")return"any";try{if(t.type)switch(t.type){case"string":return"string";case"number":case"integer":return"number";case"boolean":return"boolean";case"array":return t.items?`Array<${qe(t.items,a,s+1)}>`:"any[]";case"object":if(t.properties){const c=[],u=Array.isArray(t.required)?t.required:[];for(const[h,j]of Object.entries(t.properties))try{const k=j,$=_t(h),R=u.includes(h)?"":"?",V=qe(k,a+" ",s+1),D=k&&typeof k=="object"&&k.description?`/** ${String(k.description).replace(/\*\//g,"* /")} */
12
+ ${a} `:"";c.push(`${D}${$}${R}: ${V};`)}catch(k){console.warn(`Failed to process property ${h}:`,k)}return c.length===0?"Record<string, any>":`{
13
+ ${a} ${c.join(`
14
+ ${a} `)}
15
+ ${a}}`}return"Record<string, any>";default:return"any"}if(t.anyOf&&Array.isArray(t.anyOf)){const c=t.anyOf.map(u=>qe(u,a,s+1)).filter(u=>u&&u!=="any");return c.length>0?c.join(" | "):"any"}if(t.oneOf&&Array.isArray(t.oneOf)){const c=t.oneOf.map(u=>qe(u,a,s+1)).filter(u=>u&&u!=="any");return c.length>0?c.join(" | "):"any"}if(t.allOf&&Array.isArray(t.allOf)){const c={type:"object",properties:{},required:[]};for(const u of t.allOf)u&&typeof u=="object"&&u.properties&&(c.properties={...c.properties,...u.properties}),u&&typeof u=="object"&&Array.isArray(u.required)&&(c.required=[...c.required||[],...u.required]);return qe(c,a,s+1)}return Array.isArray(t.enum)?t.enum.map(c=>typeof c=="string"?Me(c):JSON.stringify(c)).join(" | "):"any"}catch(c){return console.warn("Error converting JSON Schema to TypeScript:",c,t),"any"}}function so(t){try{const{config:a,mcpTools:s=[],tables:c=[]}=t,u=a.variables.length>0?`type VarName = ${a.variables.map(C=>Me(C.name)).join(" | ")};
16
+
17
+ `:"",h=c.map(C=>{const le=`${Ue(C.name)}TableRow`,J=C.columns.map(Z=>{const _=_t(Z.name),$e={string:"string",number:"number",boolean:"boolean",date:"string",json:"any"}[Z.type]||"any",me=Z.nullable?`${$e} | null`:$e,we=Z.nullable?"?":"";return` ${_}${we}: ${me};`}).join(`
18
+ `);return`type ${le} = {
19
+ ${J}
20
+ };
21
+ `}).join(`
22
+ `),j=c.length>0?`type TableName = ${c.map(C=>Me(C.name)).join(" | ")};
23
+
24
+ `:"",k=s.length>0?`type ToolName = ${s.map(C=>{const B=C.originalToolName||C.name;return Me(B)}).join(" | ")};
25
+
26
+ `:"",$=new Map;s.filter(C=>C&&C.name).forEach(C=>{try{const B=C.name||"Unknown",le=qe(C.inputSchema||{type:"object",properties:{}}),J=Gt(B);if(!J||J.trim()===""){console.warn(`[Context Types] Invalid type name for tool: ${B}`);return}const Z=`${J}Args`;if(!$.has(Z))$.set(Z,`type ${Z} = ${le};`);else{const _=$.get(Z);_&&_!==`type ${Z} = ${le};`&&console.warn(`[Context Types] Type ${Z} already exists with different definition for tool: ${B}`)}}catch(B){console.warn(`[Context Types] Failed to generate type for tool ${C==null?void 0:C.name}:`,B)}});const P=Array.from($.values()).join(`
27
+ `),R=P?`${P}
28
+
29
+ `:"",V=s.filter(C=>C&&C.name).map(C=>{try{const B=C.originalToolName||C.name,le=Me(B),J=C.name||"Unknown",Z=Gt(J);if(!Z||Z.trim()==="")return console.warn(`[Context Types] Invalid type name for tool: ${J}, skipping overload`),null;const _=`${Z}Args`;return $.has(_)||console.warn(`[Context Types] Type ${_} not found in type definitions for tool: ${J}`),`${C.description?` /**
30
+ * ${C.description.replace(/\*\//g,"* /")}
31
+ *
32
+ * @param toolName - 工具名称
33
+ * @param args - 工具参数
34
+ */
35
+ `:" "}callTool(toolName: ${le}, args: ${_}): Promise<any>;`}catch(B){return console.warn(`Failed to generate overload for tool ${C==null?void 0:C.name}:`,B),null}}).filter(C=>C!==null).join(`
36
+ `),D=s.length>0?`${V}
37
+ /**
38
+ * 调用 MCP 工具
39
+ *
40
+ * @param toolName - 工具名称
41
+ * @param args - 工具参数
42
+ */
43
+ callTool(toolName: ToolName, args: any): Promise<any>;`:`/**
44
+ * 调用 MCP 工具
45
+ *
46
+ * @param toolName - 工具名称
47
+ * @param args - 工具参数
48
+ */
49
+ callTool(toolName: string, args: any): Promise<any>;`,L=a.variables.length>0?"get(name: VarName): string;":"get(name: string): string;",Y=c.map(C=>{const le=`${Ue(C.name)}TableRow`;return` /**
50
+ * 获取指定表的所有数据行
51
+ *
52
+ * @param tableName - 表名
53
+ * @returns 返回该表的所有数据行数组,每行是一个包含列数据的对象
54
+ *
55
+ * @example
56
+ * // 获取 users 表的所有数据
57
+ * const allUsers = await context.tables.get('users');
58
+ *
59
+ * @example
60
+ * // 遍历所有用户
61
+ * const users = await context.tables.get('users');
62
+ * for (const user of users) {
63
+ * console.log(user.name, user.email);
64
+ * }
65
+ */
66
+ get(tableName: ${Me(C.name)}): Promise<Array<${le}>>;`}).join(`
67
+ `),H=c.length>0?`${Y}
68
+ /**
69
+ * 获取指定表的所有数据行
70
+ *
71
+ * @param tableName - 表名
72
+ * @returns 返回该表的所有数据行数组,每行是一个包含列数据的对象
73
+ *
74
+ * @example
75
+ * // 获取 users 表的所有数据
76
+ * const allUsers = await context.tables.get('users');
77
+ */
78
+ get(tableName: TableName): Promise<Array<Record<string, any>>>;`:`/**
79
+ * 获取指定表的所有数据行
80
+ *
81
+ * @param tableName - 表名
82
+ * @returns 返回该表的所有数据行数组,每行是一个包含列数据的对象
83
+ *
84
+ * @example
85
+ * // 获取 users 表的所有数据
86
+ * const allUsers = await context.tables.get('users');
87
+ */
88
+ get(tableName: string): Promise<Array<Record<string, any>>>;`,z=c.map(C=>{const le=`${Ue(C.name)}TableRow`;return` /**
89
+ * 查询指定表的数据,支持使用过滤函数筛选行
90
+ *
91
+ * @param tableName - 表名
92
+ * @param filter - 可选的过滤函数,接收一行数据作为参数,返回 true 表示保留该行
93
+ * @returns 返回符合过滤条件的数据行数组
94
+ *
95
+ * @example
96
+ * // 查询所有年龄大于 18 的用户
97
+ * const adults = await context.tables.query('users', (row) => row.age > 18);
98
+ *
99
+ * @example
100
+ * // 查询所有活跃用户
101
+ * const activeUsers = await context.tables.query('users', (row) => row.isActive === true);
102
+ *
103
+ * @example
104
+ * // 不传过滤函数,等同于 get(),返回所有数据
105
+ * const allUsers = await context.tables.query('users');
106
+ */
107
+ query(tableName: ${Me(C.name)}, filter?: (row: ${le}) => boolean): Promise<Array<${le}>>;`}).join(`
108
+ `),U=c.length>0?`${z}
109
+ /**
110
+ * 查询指定表的数据,支持使用过滤函数筛选行
111
+ *
112
+ * @param tableName - 表名
113
+ * @param filter - 可选的过滤函数,接收一行数据作为参数,返回 true 表示保留该行
114
+ * @returns 返回符合过滤条件的数据行数组
115
+ *
116
+ * @example
117
+ * // 查询所有年龄大于 18 的用户
118
+ * const adults = await context.tables.query('users', (row) => row.age > 18);
119
+ */
120
+ query(tableName: TableName, filter?: (row: Record<string, any>) => boolean): Promise<Array<Record<string, any>>>;`:`/**
121
+ * 查询指定表的数据,支持使用过滤函数筛选行
122
+ *
123
+ * @param tableName - 表名
124
+ * @param filter - 可选的过滤函数,接收一行数据作为参数,返回 true 表示保留该行
125
+ * @returns 返回符合过滤条件的数据行数组
126
+ *
127
+ * @example
128
+ * // 查询所有年龄大于 18 的用户
129
+ * const adults = await context.tables.query('users', (row) => row.age > 18);
130
+ */
131
+ query(tableName: string, filter?: (row: Record<string, any>) => boolean): Promise<Array<Record<string, any>>>;`;return`
132
+ ${u}${h}${j}${R}${k}declare interface Context {
133
+ user: {
134
+ id: string;
135
+ email: string;
136
+ role: 'admin' | 'user';
137
+ createdAt: Date;
138
+ updatedAt: Date;
139
+ };
140
+ http: {
141
+ get(url: string, options?: any): Promise<any>;
142
+ post(url: string, data?: any, options?: any): Promise<any>;
143
+ put(url: string, data?: any, options?: any): Promise<any>;
144
+ delete(url: string, options?: any): Promise<any>;
145
+ };
146
+ fs: {
147
+ readFile(path: string): Promise<string>;
148
+ writeFile(path: string, content: string): Promise<void>;
149
+ exists(path: string): Promise<boolean>;
150
+ listDir(path: string): Promise<string[]>;
151
+ mkdir(path: string): Promise<void>;
152
+ isFile(path: string): Promise<boolean>;
153
+ };
154
+ cmd: {
155
+ exec(command: string, options?: { cwd?: string; timeout?: number }): Promise<{ stdout: string; stderr: string; exitCode: number }>;
156
+ };
157
+ utils: {
158
+ md5(input: string): string;
159
+ };
160
+ ripgrep: {
161
+ /**
162
+ * 搜索文件内容
163
+ */
164
+ search(
165
+ pattern: string,
166
+ options?: {
167
+ /** 工作目录(相对于用户隔离目录) */
168
+ cwd?: string;
169
+ /** 是否大小写敏感 */
170
+ caseSensitive?: boolean;
171
+ /** 是否启用多行匹配 */
172
+ multiline?: boolean;
173
+ /** 文件过滤模式(glob 模式数组) */
174
+ files?: string[];
175
+ /** 排除文件模式(glob 模式数组) */
176
+ excludeFiles?: string[];
177
+ /** 每个文件的最大匹配数 */
178
+ maxCount?: number;
179
+ /** 总结果数的最大限制 */
180
+ maxResults?: number;
181
+ /** 最大递归深度 */
182
+ maxDepth?: number;
183
+ /** 匹配行之前显示的行数 */
184
+ contextBefore?: number;
185
+ /** 匹配行之后显示的行数 */
186
+ contextAfter?: number;
187
+ /** 匹配行前后显示的行数(等同于同时设置 contextBefore 和 contextAfter) */
188
+ context?: number;
189
+ /** 将模式视为固定字符串而非正则表达式 */
190
+ fixedStrings?: boolean;
191
+ /** 只匹配完整的单词 */
192
+ wordRegexp?: boolean;
193
+ /** 文件类型过滤(如:['js', 'ts']) */
194
+ fileTypes?: string[];
195
+ /** 排除的文件类型 */
196
+ excludeTypes?: string[];
197
+ /** 只返回包含匹配的文件名 */
198
+ filesWithMatches?: boolean;
199
+ /** 只返回每个文件的匹配数量 */
200
+ count?: boolean;
201
+ /** 忽略 .gitignore 和 .ignore 文件 */
202
+ noIgnore?: boolean;
203
+ /** 智能大小写:如果模式包含大写字母则大小写敏感 */
204
+ smartCase?: boolean;
205
+ }
206
+ ): Promise<Array<{ file: string; line: number; text: string; column?: number; contextBefore?: string[]; contextAfter?: string[] }>>;
207
+
208
+ /**
209
+ * 通过文件名模式搜索文件
210
+ */
211
+ searchByPath(
212
+ pattern: string,
213
+ options?: {
214
+ /** 工作目录(相对于用户隔离目录) */
215
+ cwd?: string;
216
+ /** 是否大小写敏感 */
217
+ caseSensitive?: boolean;
218
+ /** 最大递归深度 */
219
+ maxDepth?: number;
220
+ /** 文件类型过滤(如:['js', 'ts']) */
221
+ fileTypes?: string[];
222
+ /** 排除的文件类型 */
223
+ excludeTypes?: string[];
224
+ /** 排除文件模式(glob 模式数组) */
225
+ excludeFiles?: string[];
226
+ /** 总结果数的最大限制 */
227
+ maxResults?: number;
228
+ /** 忽略 .gitignore 和 .ignore 文件 */
229
+ noIgnore?: boolean;
230
+ }
231
+ ): Promise<string[]>;
232
+ };
233
+ mcp: {
234
+ ${D}
235
+ listTools(): Promise<string[]>;
236
+ };
237
+ vars: {
238
+ ${L}
239
+ has(name: string): boolean;
240
+ getAll(): Record<string, string>;
241
+ set(name: string, value: string, description?: string): void;
242
+ };
243
+ log: {
244
+ info(message: string, ...args: any[]): void;
245
+ error(message: string, ...args: any[]): void;
246
+ warn(message: string, ...args: any[]): void;
247
+ debug(message: string, ...args: any[]): void;
248
+ };
249
+ tables: {
250
+ /**
251
+ * 列出当前用户的所有表定义
252
+ *
253
+ * @returns 返回表定义数组,每个表定义包含:
254
+ * - id: 表的唯一标识符
255
+ * - name: 表名
256
+ * - description: 表的描述(可选)
257
+ * - columns: 列定义数组,每个列包含 name(列名)、type(类型)、nullable(是否可为空)
258
+ *
259
+ * @example
260
+ * // 获取所有表定义
261
+ * const tables = await context.tables.list();
262
+ * console.log('共有', tables.length, '张表');
263
+ *
264
+ * @example
265
+ * // 遍历所有表并打印表名和列信息
266
+ * const tables = await context.tables.list();
267
+ * for (const table of tables) {
268
+ * console.log('表名:', table.name);
269
+ * console.log('列数:', table.columns.length);
270
+ * table.columns.forEach(col => {
271
+ * console.log(' -', col.name + ':', col.type + (col.nullable ? ' (可为空)' : ''));
272
+ * });
273
+ * }
274
+ */
275
+ list(): Promise<Array<{ id: string; name: string; description?: string; columns: Array<{ name: string; type: string; nullable: boolean }> }>>;
276
+ ${H}
277
+ ${U}
278
+ };
279
+ }
280
+ `}catch(a){return console.error("Error generating context type definition:",a),`
281
+ declare interface Context {
282
+ user: {
283
+ id: string;
284
+ email: string;
285
+ role: 'admin' | 'user';
286
+ createdAt: Date;
287
+ updatedAt: Date;
288
+ };
289
+ http: {
290
+ get(url: string, options?: any): Promise<any>;
291
+ post(url: string, data?: any, options?: any): Promise<any>;
292
+ put(url: string, data?: any, options?: any): Promise<any>;
293
+ delete(url: string, options?: any): Promise<any>;
294
+ };
295
+ fs: {
296
+ readFile(path: string): Promise<string>;
297
+ writeFile(path: string, content: string): Promise<void>;
298
+ exists(path: string): Promise<boolean>;
299
+ listDir(path: string): Promise<string[]>;
300
+ mkdir(path: string): Promise<void>;
301
+ isFile(path: string): Promise<boolean>;
302
+ };
303
+ cmd: {
304
+ exec(command: string, options?: { cwd?: string; timeout?: number }): Promise<{ stdout: string; stderr: string; exitCode: number }>;
305
+ };
306
+ utils: {
307
+ md5(input: string): string;
308
+ };
309
+ mcp: {
310
+ callTool(toolName: string, args: any): Promise<any>;
311
+ listTools(): Promise<string[]>;
312
+ };
313
+ vars: {
314
+ get(name: string): string;
315
+ has(name: string): boolean;
316
+ getAll(): Record<string, string>;
317
+ set(name: string, value: string, description?: string): void;
318
+ };
319
+ log: {
320
+ info(message: string, ...args: any[]): void;
321
+ error(message: string, ...args: any[]): void;
322
+ warn(message: string, ...args: any[]): void;
323
+ debug(message: string, ...args: any[]): void;
324
+ };
325
+ tables: {
326
+ list(): Promise<Array<{ id: string; name: string; description?: string; columns: Array<{ name: string; type: string; nullable: boolean }> }>>;
327
+ get(tableName: string): Promise<Array<Record<string, any>>>;
328
+ query(tableName: string, filter?: (row: Record<string, any>) => boolean): Promise<Array<Record<string, any>>>;
329
+ };
330
+ }
331
+ `}}function ro(t){const{tables:a=[]}=t,s="callTool(toolName: any, args: any): Promise<any>;",c=a.map(P=>{const V=`${Ue(P.name)}TableRow`,D=P.columns.map(L=>{const Y=_t(L.name),z={string:"string",number:"number",boolean:"boolean",date:"string",json:"any"}[L.type]||"any",U=L.nullable?`${z} | null`:z,C=L.nullable?"?":"";return` ${Y}${C}: ${U};`}).join(`
332
+ `);return`type ${V} = {
333
+ ${D}
334
+ };`}).join(`
335
+
336
+ `),u=c?`${c}
337
+
338
+ `:"",h=a.map(P=>{const V=`${Ue(P.name)}TableRow`;return` get(tableName: ${Me(P.name)}): Promise<Array<${V}>>;`}).join(`
339
+ `),j=a.length>0?`${h}
340
+ get(tableName: string): Promise<Array<Record<string, any>>>;`:"get(tableName: string): Promise<Array<Record<string, any>>>;",k=a.map(P=>{const V=`${Ue(P.name)}TableRow`;return` query(tableName: ${Me(P.name)}, filter?: (row: ${V}) => boolean): Promise<Array<${V}>>;`}).join(`
341
+ `),$=a.length>0?`${k}
342
+ query(tableName: string, filter?: (row: Record<string, any>) => boolean): Promise<Array<Record<string, any>>>;`:"query(tableName: string, filter?: (row: Record<string, any>) => boolean): Promise<Array<Record<string, any>>>;";return`${u}declare interface Context {
343
+ user: {
344
+ id: string;
345
+ email: string;
346
+ role: 'admin' | 'user';
347
+ createdAt: Date;
348
+ updatedAt: Date;
349
+ };
350
+ http: {
351
+ get(url: string, options?: any): Promise<any>;
352
+ post(url: string, data?: any, options?: any): Promise<any>;
353
+ put(url: string, data?: any, options?: any): Promise<any>;
354
+ delete(url: string, options?: any): Promise<any>;
355
+ };
356
+ fs: {
357
+ readFile(path: string): Promise<string>;
358
+ writeFile(path: string, content: string): Promise<void>;
359
+ exists(path: string): Promise<boolean>;
360
+ listDir(path: string): Promise<string[]>;
361
+ mkdir(path: string): Promise<void>;
362
+ isFile(path: string): Promise<boolean>;
363
+ };
364
+ cmd: {
365
+ exec(command: string, options?: { cwd?: string; timeout?: number }): Promise<{ stdout: string; stderr: string; exitCode: number }>;
366
+ };
367
+ utils: {
368
+ md5(input: string): string;
369
+ };
370
+ ripgrep: {
371
+ search(pattern: string, options?: any): Promise<Array<{ file: string; line: number; text: string; column?: number; contextBefore?: string[]; contextAfter?: string[] }>>;
372
+ searchByPath(pattern: string, options?: any): Promise<string[]>;
373
+ };
374
+ mcp: {
375
+ ${s}
376
+ listTools(): Promise<string[]>;
377
+ };
378
+ vars: {
379
+ get(name: string): string;
380
+ has(name: string): boolean;
381
+ getAll(): Record<string, string>;
382
+ set(name: string, value: string, description?: string): void;
383
+ };
384
+ log: {
385
+ info(message: string, ...args: any[]): void;
386
+ error(message: string, ...args: any[]): void;
387
+ warn(message: string, ...args: any[]): void;
388
+ debug(message: string, ...args: any[]): void;
389
+ };
390
+ tables: {
391
+ list(): Promise<Array<{ id: string; name: string; description?: string; columns: Array<{ name: string; type: string; nullable: boolean }> }>>;
392
+ ${j}
393
+ ${$}
394
+ };
395
+ }
396
+ `}function ao(t){const{contextTypeDef:a,toolArgsType:s,functionBody:c,hasCustomImplementation:u,toolName:h,toolDescription:j,functionParams:k="both"}=t,$=(D=!1)=>{const L=D?c:" // 在此处实现";return k==="both"?`export default async function(args: ToolArgs, context: Context) {
397
+ ${L}
398
+ }`:k==="args"?`export default async function(args: ToolArgs) {
399
+ ${L}
400
+ }`:`export default async function(context: Context) {
401
+ ${L}
402
+ }`},P=()=>k==="both"?"- 只能使用 args 和 context 参数中的 API":k==="args"?"- 只能使用 args 参数中的 API":"- 只允许使用 context 参数中的 API",R=()=>u?h&&j?`请帮我调整/优化以下函数的实现。工具名称:${h},描述:${j}。`:"请帮我调整/优化以下函数的实现。":h&&j?`请帮我实现以下函数。工具名称:${h},描述:${j}。`:"请帮我实现以下函数。",V=()=>{const D=[];return s&&D.push(`### ToolArgs 类型定义
403
+
404
+ \`\`\`typescript
405
+ ${s}
406
+ \`\`\``),D.push(`### Context 类型定义
407
+
408
+ \`\`\`typescript
409
+ ${a}
410
+ \`\`\``),D.join(`
411
+
412
+ `)};return u?`${R()}
413
+
414
+ ## 类型定义
415
+
416
+ ${V()}
417
+
418
+ ## 当前实现
419
+
420
+ \`\`\`typescript
421
+ ${$(!0)}
422
+ \`\`\`
423
+
424
+ ## 输出格式
425
+
426
+ 只输出以下函数定义代码(类型部分不必输出),格式如下:
427
+
428
+ \`\`\`typescript
429
+ ${$(!1)}
430
+ \`\`\`
431
+
432
+ 不要输出任何注释、解释文字或其他内容。
433
+
434
+ ## 约束
435
+
436
+ ${P()}`:`${R()}
437
+
438
+ ## 类型定义
439
+
440
+ ${V()}
441
+
442
+ ## 函数签名
443
+
444
+ \`\`\`typescript
445
+ ${$(!1)}
446
+ \`\`\`
447
+
448
+ ## 输出格式
449
+
450
+ 只输出以下函数定义代码(类型部分不必输出),格式如下:
451
+
452
+ \`\`\`typescript
453
+ ${$(!1)}
454
+ \`\`\`
455
+
456
+ 不要输出任何注释、解释文字或其他内容。
457
+
458
+ ## 约束
459
+
460
+ ${P()}`}const xs={class:"tools-manager"},Ts={class:"tools-toolbar"},Ss={class:"tools-table-container"},$s={class:"modal-header"},Ps={class:"modal-title"},js={class:"modal-subtitle"},Ns={class:"modal-content-wrapper"},Os={class:"tab-pane-content"},Ms={class:"form-section"},As={class:"form-grid-2"},Ds={class:"form-section"},zs={class:"section-header"},_s={class:"parameters-list"},Es={class:"parameter-header"},Fs={class:"parameter-index"},Us={class:"parameter-fields"},Bs={key:0,class:"empty-parameters"},Js={class:"tab-pane-content"},Is={class:"save-status-indicator"},Rs=["title"],Vs={key:0,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},Ls={key:1,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},qs={class:"monaco-wrapper"},Hs={class:"modal-footer"},Ks={class:"test-args-content"},Gs={key:0,class:"test-args-parameters"},Ws={class:"parameters-header"},Zs={class:"parameters-count"},Qs={class:"test-args-input-wrapper"},Ys={class:"test-args-input-header"},Xs={viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{width:"14px",height:"14px"}},er={key:1,class:"test-result-section"},tr={class:"test-result-header"},or={class:"test-result-title"},nr={viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{width:"18px",height:"18px","margin-right":"8px"}},sr={class:"test-result-actions"},rr={viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{width:"16px",height:"16px"}},ar={viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{width:"16px",height:"16px"}},lr={class:"test-result-content"},ir={class:"test-result-pre"},cr={class:"test-result-code-inner"},ur={class:"modal-footer"},Re=`/**
461
+ * 工具脚本
462
+ * @param args 工具参数对象 (类型根据 Schema 声明自动生成)
463
+ * @param context 上下文对象 (提供常用工具方法等)
464
+ */
465
+ export default async function (args: ToolArgs, context: Context) {
466
+ const { log } = context;
467
+
468
+ log.info('工具执行中');
469
+
470
+ return {
471
+ // 返回结果
472
+ };
473
+ }
474
+ `,dr=ht({__name:"CustomToolsManager",props:{config:{}},emits:["update"],setup(t,{emit:a}){const s=t,c=a,u=Dt(),h=A(!1),j=A(!1),k=A(null),$=A(),P=A(""),R=A("schema"),V=A(!1),D=A(!1),L=A(""),Y=A(!1),H=A("{}"),z=A(null),U=A(!1),C=Te(()=>O.value.serverScript!==L.value),B=Te(()=>V.value?"height: calc(100vh - 120px); border-radius: 12px; overflow: hidden;":"height: 474px; border-radius: 12px; overflow: hidden;"),le=A([]),J=A([]),Z=v=>v?`custom_tool_script_${v}`:"custom_tool_script_new",_=v=>{const r=Z(v),y=localStorage.getItem(r);return y||null},ge=(v,r)=>{const y=Z(v);localStorage.setItem(y,r)},$e=v=>{const r=Z(v);localStorage.removeItem(r)},me=v=>v?`custom_tool_test_args_${v}`:"custom_tool_test_args_new",we=v=>{const r=me(v);return localStorage.getItem(r)},de=(v,r)=>{const y=me(v);localStorage.setItem(y,r)},Be={pageSize:10,showSizePicker:!0,pageSizes:[10,20,50]},Ce=v=>({style:"cursor: pointer; transition: all 0.2s ease;",onMouseenter:r=>{r.currentTarget.style.backgroundColor="rgba(99, 102, 241, 0.04)"},onMouseleave:r=>{r.currentTarget.style.backgroundColor=""}}),Se=[{title:"参数名",key:"name",width:150},{title:"类型",key:"type",width:100},{title:"必需",key:"required",width:80,render:v=>v.required?ve(Bt,{type:"error"},{default:()=>"是"}):"否"},{title:"描述",key:"description",ellipsis:{tooltip:!0}}],l=[{title:"工具名称",key:"name",width:300,render(v){const r=ve("div",{style:"display: flex; align-items: center; gap: 10px;"},[ve("div",{style:"width: 32px; height: 32px; border-radius: 50%; background: #e3f2fd; color: #1565c0; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 14px; flex-shrink: 0;"},v.name.charAt(0).toUpperCase()),ve("div",{style:"display: flex; flex-direction: column;"},[ve("span",{style:"font-weight: 500;"},v.name)])]);return!v.parameters||v.parameters.length===0?r:ve("div",{style:"display: flex; align-items: center; justify-content: space-between;"},[r,ve(Jt,{trigger:"hover",style:"max-width: 600px; max-height: 500px; padding: 0; overflow: hidden;"},{trigger:()=>ve(G,{size:"tiny",tertiary:!0,circle:!0,type:"info"},{default:()=>"📄"}),default:()=>ve("div",{style:"max-height: 500px; overflow-y: auto;"},[ve(Pt,{size:"small",bordered:!1,columns:[{title:"参数名",key:"name",width:120},{title:"类型",key:"type",width:80},{title:"必需",key:"required",width:60,render:y=>y.required?ve(Bt,{type:"error"},{default:()=>"是"}):"否"},{title:"描述",key:"description"}],data:v.parameters,pagination:!1,singleLine:!1})])})])}},{title:"脚本",key:"script",width:150,render(v){return v.serverScript?ve(Jt,{trigger:"hover",placement:"right",style:"max-width: 600px; max-height: 500px; overflow: hidden;"},{trigger:()=>ve(Xe,{type:"info",size:"small",bordered:!0,style:"cursor: pointer;"},{default:()=>"Typescript"}),default:()=>ve(wo,{code:v.serverScript,language:"typescript",style:"max-height: 500px; overflow-y: auto; font-size: 12px; display: block;"})}):ve(Xe,{type:"default",size:"small",bordered:!0},{default:()=>"None"})}},{title:"描述",key:"description",ellipsis:{tooltip:!0}},{title:"操作",key:"actions",width:150,render(v){return ve(bo,{size:"small"},{default:()=>[ve(G,{size:"small",onClick:()=>st(v)},{default:()=>"编辑"}),ve(G,{size:"small",type:"error",onClick:()=>rt(v.id)},{default:()=>"删除"})]})}}],K=Te(()=>{const v=s.config.customTools.filter(y=>(y.source||"custom")==="custom");if(!P.value)return v;const r=P.value.toLowerCase();return v.filter(y=>y.name.toLowerCase().includes(r)||y.description.toLowerCase().includes(r))});async function ee(){try{const v=await ue.get("/configs/all-tools");v.data.success&&v.data.data.tools?le.value=v.data.data.tools:le.value=[]}catch(v){console.error("Failed to load MCP tools from database:",v),le.value=[]}}async function Ne(){try{const v=await ue.get("/tables/definitions");v.data.success&&(J.value=v.data.data||[])}catch(v){console.error("Failed to load tables:",v),J.value=[]}}const Pe=Te(()=>{let v=le.value;if(k.value&&O.value.name){const r={name:O.value.name,description:O.value.description||"",inputSchema:{type:"object",properties:O.value.parameters.reduce((y,Q)=>(Q.name&&Q.name.trim()&&(y[Q.name.trim()]={type:Q.type,description:Q.description||""}),y),{}),required:O.value.parameters.filter(y=>y.required).map(y=>y.name.trim())}};v=v.filter(y=>y.name!==O.value.name).concat(r)}return so({config:s.config,mcpTools:v,tables:J.value})}),_e=Te(()=>!O.value.parameters||O.value.parameters.length===0?`
475
+ /**
476
+ * 工具参数类型
477
+ */
478
+ declare interface ToolArgs {
479
+ [key: string]: any;
480
+ }
481
+ `:`
482
+ /**
483
+ * 工具参数类型
484
+ * 根据 Schema 声明自动生成
485
+ */
486
+ declare interface ToolArgs {
487
+ ${O.value.parameters.filter(r=>r.name&&r.name.trim()).map(r=>{const y=r.name.trim(),ie=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(y)?y:`"${y.replace(/"/g,'\\"')}"`,xe=r.required?"":"?",i=r.description?`/** ${r.description.replace(/\*\//g,"* /")} */
488
+ `:"";let e="any";switch(r.type){case"string":e="string";break;case"number":e="number";break;case"boolean":e="boolean";break;case"object":e="Record<string, any>";break;case"array":e="any[]";break;default:e="any"}return`${i}${ie}${xe}: ${e};`}).join(`
489
+ `)}
490
+ }
491
+ `),Oe=A(0),ot=Te(()=>[{content:Pe.value,filePath:"file:///context.d.ts"},{content:_e.value,filePath:"file:///tool-args.d.ts"}]),O=A({name:"",description:"",serverScript:Re,parameters:[]}),He=[{label:"string",value:"string"},{label:"number",value:"number"},{label:"boolean",value:"boolean"},{label:"object",value:"object"},{label:"array",value:"array"}],wt={name:{required:!0,message:"请输入工具名称",trigger:"blur"},description:{required:!0,message:"请输入描述",trigger:"blur"}};function bt(){return{name:"",type:"string",description:"",required:!1}}function nt(){const v={};return O.value.parameters.forEach(r=>{if(r.name&&r.name.trim())switch(r.type){case"number":v[r.name]=0;break;case"boolean":v[r.name]=!1;break;case"array":v[r.name]=[];break;case"object":v[r.name]={};break;default:v[r.name]=""}}),JSON.stringify(v,null,2)}function st(v){k.value=v;const y=_(v.id)||v.serverScript||Re;O.value={name:v.name,description:v.description,serverScript:y,parameters:v.parameters?JSON.parse(JSON.stringify(v.parameters)):[]},L.value=v.serverScript||"",h.value=!0}function rt(v){const r=s.config.customTools.filter(y=>y.id!==v);c("update",{customTools:r})}async function kt(){var v,r,y;try{if(await((v=$.value)==null?void 0:v.validate()),j.value=!0,!O.value.serverScript)throw new Error("脚本不能为空");const Q={id:((r=k.value)==null?void 0:r.id)||Qe(),name:O.value.name,description:O.value.description,serverScript:O.value.serverScript,parameters:O.value.parameters,source:((y=k.value)==null?void 0:y.source)||"custom"},ie=[...s.config.customTools],xe=ie.findIndex(i=>i.id===Q.id);xe!==-1?ie[xe]=Q:ie.push(Q),c("update",{customTools:ie}),$e(Q.id),$e(null),h.value=!1,We()}catch(Q){u.error(Q.message)}finally{j.value=!1}}function Ct(v){var y;const r=((y=k.value)==null?void 0:y.id)||null;ge(r,v)}function Ke(){var r;L.value=O.value.serverScript;const v=((r=k.value)==null?void 0:r.id)||null;ge(v,O.value.serverScript),u.success("脚本已保存")}async function xt(){var v,r,y,Q,ie,xe;if(!O.value.serverScript.trim()){u.warning("请先编写脚本内容"),Y.value=!1;return}Ke(),D.value=!0,z.value=null,U.value=!1;try{let i={};try{const n=H.value.trim()||"{}";if(i=JSON.parse(n),typeof i!="object"||Array.isArray(i))throw new Error("参数必须是 JSON 对象")}catch(n){u.error(`参数格式错误: ${n.message}`),D.value=!1;return}const e=await ue.post("/configs/test-custom-tool",{script:O.value.serverScript,args:i,toolName:O.value.name||"test-tool"});if(e.data.success){const n=((v=k.value)==null?void 0:v.id)||null;de(n,H.value);const w=(r=e.data.data)==null?void 0:r.result;z.value=w,U.value=!0,u.success("测试执行成功")}else z.value={error:e.data.error,success:!1},U.value=!0,u.error(`测试执行失败: ${e.data.error}`)}catch(i){z.value={error:((Q=(y=i.response)==null?void 0:y.data)==null?void 0:Q.error)||i.message,success:!1},U.value=!0,u.error(`测试执行失败: ${((xe=(ie=i.response)==null?void 0:ie.data)==null?void 0:xe.error)||i.message}`)}finally{D.value=!1}}function he(v){try{return JSON.stringify(v,null,2)}catch{return String(v)}}async function Je(){if(z.value)try{const v=he(z.value);await navigator.clipboard.writeText(v),u.success("测试结果已复制到剪贴板")}catch{try{const r=he(z.value),y=document.createElement("textarea");y.value=r,y.style.position="fixed",y.style.left="-999999px",y.style.top="-999999px",document.body.appendChild(y),y.focus(),y.select();const Q=document.execCommand("copy");document.body.removeChild(y),Q?u.success("测试结果已复制到剪贴板"):u.error("复制失败,请手动复制")}catch{u.error("复制失败,请手动复制")}}}function at(){H.value=nt(),u.info("已重置为默认参数")}function lt(){Y.value=!1,z.value=null,U.value=!1}function it(){V.value=!V.value}function Ge(v){const r=v.match(/export\s+default\s+async\s+function\s*(\w+)?\s*\([^)]*\)\s*\{([\s\S]*)\}/);return r&&r[1]?r[1].trim():v}async function Ie(){try{let v=le.value;if(k.value&&O.value.name){const g={name:O.value.name,description:O.value.description||"",inputSchema:{type:"object",properties:O.value.parameters.reduce((f,S)=>(S.name&&S.name.trim()&&(f[S.name.trim()]={type:S.type,description:S.description||""}),f),{}),required:O.value.parameters.filter(f=>f.required).map(f=>f.name.trim())}};v=v.filter(f=>f.name!==O.value.name).concat(g)}const r=ro({config:s.config,mcpTools:v,tables:J.value}),y=O.value.parameters.length>0?`type ToolArgs = {
492
+ ${O.value.parameters.filter(g=>g.name&&g.name.trim()).map(g=>{const f=g.required?"":"?",x={string:"string",number:"number",boolean:"boolean",array:"any[]",object:"Record<string, any>"}[g.type]||"any",b=g.description?` /** ${g.description} */`:"";return` ${g.name.trim()}${f}: ${x};${b}`}).join(`
493
+ `)}
494
+ };`:"type ToolArgs = Record<string, any>;",Q=O.value.serverScript.trim()||Re,ie=Ge(Q),xe=Ge(Re),i=Q!==Re&&ie!==xe,e=O.value.name||"未命名工具",n=O.value.description||"无描述",w=ao({contextTypeDef:r,toolArgsType:y,functionBody:ie,hasCustomImplementation:i,toolName:e,toolDescription:n,functionParams:"both"});await navigator.clipboard.writeText(w),u.success("提示词已复制到剪贴板!")}catch(v){console.error("Failed to copy prompt:",v),u.error("复制失败,请手动复制")}}function We(){k.value=null,R.value="schema",V.value=!1,Y.value=!1,H.value="{}",z.value=null,U.value=!1;const v=_(null);O.value={name:"",description:"",serverScript:v||Re,parameters:[]},L.value=""}return At(()=>{ee(),Ne()}),ke(()=>s.config.components,()=>{ee()},{deep:!0}),ke(()=>R.value,v=>{v==="implementation"&&Fe(()=>{Oe.value++})}),ke(()=>O.value.parameters,()=>{Fe(()=>{Oe.value++})},{deep:!0,immediate:!1}),ke(()=>[O.value.name,O.value.description],()=>{Fe(()=>{Oe.value++})},{immediate:!1}),ke(()=>Y.value,v=>{var r;if(v){const y=((r=k.value)==null?void 0:r.id)||null,Q=we(y);Q?H.value=Q:H.value=nt()}}),ke(()=>s.config.customTools,()=>{ee()},{deep:!0}),ke(()=>h.value,v=>{if(v){if(!k.value){const r=_(null);r&&(O.value.serverScript=r)}}else We()}),(v,r)=>(F(),q("div",xs,[o("div",Ts,[m(p(G),{type:"primary",size:"large",class:"add-tool-btn",onClick:r[0]||(r[0]=y=>h.value=!0)},{icon:d(()=>[...r[13]||(r[13]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M12 4v16m8-8H4",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:d(()=>[r[14]||(r[14]=I(" 添加工具 ",-1))]),_:1}),m(p(be),{value:P.value,"onUpdate:value":r[1]||(r[1]=y=>P.value=y),placeholder:"搜索工具名称或描述...",size:"large",clearable:"",class:"search-input"},{prefix:d(()=>[...r[15]||(r[15]=[o("svg",{class:"search-icon",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),_:1},8,["value"])]),o("div",Ss,[m(p(Pt),{columns:l,data:K.value,pagination:Be,"row-props":Ce,class:"modern-table"},null,8,["data"])]),m(p(vt),{show:h.value,"onUpdate:show":r[9]||(r[9]=y=>h.value=y),preset:"card",bordered:!1,class:"tool-edit-modal",style:{width:"90vw",maxWidth:"1400px",height:"90vh",maxHeight:"90vh"}},{header:d(()=>[o("div",$s,[r[16]||(r[16]=o("div",{class:"modal-icon"},[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M14.7 6.3a1 1 0 000 1.4l1.6 1.6a1 1 0 001.4 0l3.77-3.77a6 6 0 01-7.94 7.94l-6.91 6.91a2.12 2.12 0 01-3-3l6.91-6.91a6 6 0 017.94-7.94l-3.76 3.76z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})])],-1)),o("div",null,[o("h3",Ps,ne(k.value?"编辑自定义工具":"创建自定义工具"),1),o("p",js,ne(k.value?"修改工具的 Schema 和实现代码":"定义工具的 Schema 并编写实现逻辑"),1)])])]),footer:d(()=>[o("div",Hs,[m(p(G),{size:"large",onClick:r[8]||(r[8]=y=>h.value=!1)},{default:d(()=>[...r[36]||(r[36]=[I("取消",-1)])]),_:1}),m(p(G),{type:"primary",size:"large",loading:j.value,onClick:kt},{default:d(()=>[I(ne(k.value?"保存修改":"创建工具"),1)]),_:1},8,["loading"])])]),default:d(()=>[o("div",Ns,[m(p(Qt),{ref_key:"formRef",ref:$,model:O.value,rules:wt,class:"tool-form"},{default:d(()=>[m(p(Zt),{value:R.value,"onUpdate:value":r[7]||(r[7]=y=>R.value=y),type:"line",animated:"",size:"large",class:"tool-config-tabs"},{default:d(()=>[m(p(gt),{name:"schema",tab:"Schema 声明"},{default:d(()=>[o("div",Os,[m(p(Le),{type:"info",bordered:!1,class:"schema-tip"},{icon:d(()=>[...r[17]||(r[17]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:d(()=>[r[18]||(r[18]=I(' 在 Schema 声明中定义的参数会自动生成类型定义,在"工具实现"标签页的脚本编辑器中可以使用类型提示 ',-1))]),_:1}),o("div",Ms,[r[21]||(r[21]=o("h4",{class:"section-title"},"基础信息",-1)),o("div",As,[m(p(fe),{path:"name"},{label:d(()=>[...r[19]||(r[19]=[o("div",{class:"form-label"},[o("svg",{class:"label-icon",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})]),o("span",null,"工具名称")],-1)])]),default:d(()=>[m(p(be),{value:O.value.name,"onUpdate:value":r[2]||(r[2]=y=>O.value.name=y),placeholder:"例如: my-custom-tool",size:"large"},null,8,["value"])]),_:1}),m(p(fe),{path:"description"},{label:d(()=>[...r[20]||(r[20]=[o("div",{class:"form-label"},[o("svg",{class:"label-icon",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})]),o("span",null,"工具描述")],-1)])]),default:d(()=>[m(p(be),{value:O.value.description,"onUpdate:value":r[3]||(r[3]=y=>O.value.description=y),placeholder:"简要描述工具的功能",size:"large"},null,8,["value"])]),_:1})])]),o("div",Ds,[o("div",zs,[r[24]||(r[24]=o("h4",{class:"section-title"},"参数定义",-1)),m(p(G),{dashed:"",onClick:r[4]||(r[4]=y=>O.value.parameters.push(bt())),size:"medium"},{icon:d(()=>[...r[22]||(r[22]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M12 4v16m8-8H4",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:d(()=>[r[23]||(r[23]=I(" 添加参数 ",-1))]),_:1})]),o("div",_s,[(F(!0),q(dt,null,pt(O.value.parameters,(y,Q)=>(F(),q("div",{key:Q,class:"parameter-card"},[o("div",Es,[o("span",Fs,"#"+ne(Q+1),1),m(p(G),{type:"error",text:"",size:"small",onClick:ie=>O.value.parameters.splice(Q,1)},{icon:d(()=>[...r[25]||(r[25]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:d(()=>[r[26]||(r[26]=I(" 删除 ",-1))]),_:1},8,["onClick"])]),o("div",Us,[m(p(fe),{label:"必填",class:"required-field"},{default:d(()=>[m(p(Xt),{checked:y.required,"onUpdate:checked":ie=>y.required=ie},null,8,["checked","onUpdate:checked"])]),_:2},1024),m(p(fe),{label:"参数名",path:`parameters[${Q}].name`,rule:{required:!0,message:"必填",trigger:"blur"}},{default:d(()=>[m(p(be),{value:y.name,"onUpdate:value":ie=>y.name=ie,placeholder:"参数名"},null,8,["value","onUpdate:value"])]),_:2},1032,["path"]),m(p(fe),{label:"类型"},{default:d(()=>[m(p(Yt),{value:y.type,"onUpdate:value":ie=>y.type=ie,options:He},null,8,["value","onUpdate:value"])]),_:2},1024),m(p(fe),{label:"描述"},{default:d(()=>[m(p(be),{value:y.description,"onUpdate:value":ie=>y.description=ie,placeholder:"参数描述"},null,8,["value","onUpdate:value"])]),_:2},1024)])]))),128)),O.value.parameters.length===0?(F(),q("div",Bs,[...r[27]||(r[27]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"2"}),o("path",{d:"M12 16v-4m0-4h.01",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round"})],-1),o("p",null,"暂无参数,点击上方按钮添加参数",-1)])])):ce("",!0)])])])]),_:1}),m(p(gt),{name:"implementation",tab:"工具实现"},{default:d(()=>[o("div",Js,[o("div",{class:Ae(["editor-container",{fullscreen:V.value}])},[o("div",Is,[o("div",{class:Ae(["status-dot",{unsaved:C.value,saved:!C.value}]),title:C.value?"未保存":"已保存"},null,10,Rs)]),m(p(G),{type:"default",size:"small",class:"fullscreen-btn",onClick:it},{icon:d(()=>[V.value?(F(),q("svg",Ls,[...r[29]||(r[29]=[o("path",{d:"M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 1 2-2h3M3 16h3a2 2 0 0 1 2 2v3",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])])):(F(),q("svg",Vs,[...r[28]||(r[28]=[o("path",{d:"M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])]))]),default:d(()=>[I(" "+ne(V.value?"退出全屏":"全屏"),1)]),_:1}),o("div",qs,[m(ft,{modelValue:O.value.serverScript,"onUpdate:modelValue":r[5]||(r[5]=y=>O.value.serverScript=y),language:"typescript",options:{minimap:{enabled:!0},fontSize:14,lineHeight:22,padding:{top:16,bottom:16},scrollBeyondLastLine:!1,automaticLayout:!0},"extra-libs":ot.value,onSave:Ke,onChange:Ct,style:Mt(B.value)},null,8,["modelValue","extra-libs","style"])])],2),o("div",{class:Ae(["editor-actions",{"fullscreen-actions":V.value}])},[m(p(G),{type:"default",size:"small",class:"copy-prompt-btn",onClick:Ie},{icon:d(()=>[...r[30]||(r[30]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M8 5.00069C7.01165 5.00069 6.49359 5.00069 6.09202 5.21967C5.71569 5.42393 5.42413 5.71549 5.21987 6.09182C5 6.49339 5 7.01145 5 7.99979V15.9998C5 16.9881 5 17.5062 5.21987 17.9078C5.42413 18.2841 5.71569 18.5757 6.09202 18.7799C6.49359 18.9998 7.01165 18.9998 8 18.9998H16C16.9883 18.9998 17.5064 18.9998 17.908 18.7799C18.2843 18.5757 18.5759 18.2841 18.7801 17.9078C19 17.5062 19 16.9881 19 15.9998V7.99979C19 7.01145 19 6.49339 18.7801 6.09182C18.5759 5.71549 18.2843 5.42393 17.908 5.21967C17.5064 5.00069 16.9883 5.00069 16 5.00069H8Z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"}),o("path",{d:"M9 3.00069C9 2.4484 9 2.17226 9.08579 1.94418C9.18885 1.67761 9.37764 1.38893 9.58579 1.18378C9.79094 0.975636 10.0796 0.786849 10.3462 0.683785C10.5743 0.598 10.8504 0.598 11.4027 0.598H14.5973C15.1496 0.598 15.4257 0.598 15.6538 0.683785C15.9204 0.786849 16.2091 0.975636 16.4142 1.18378C16.6224 1.38893 16.8111 1.67761 16.9142 1.94418C17 2.17226 17 2.4484 17 3.00069V4.00069C17 4.55297 16.5523 5.00069 16 5.00069H8C7.44772 5.00069 7 4.55297 7 4.00069V3.00069C7 2.4484 7 2.17226 7.08579 1.94418C7.18885 1.67761 7.37764 1.38893 7.58579 1.18378C7.79094 0.975636 8.07963 0.786849 8.34621 0.683785C8.57428 0.598 8.85043 0.598 9.40272 0.598H12.5973C13.1496 0.598 13.4257 0.598 13.6538 0.683785C13.9204 0.786849 14.2091 0.975636 14.4142 1.18378C14.6224 1.38893 14.8111 1.67761 14.9142 1.94418C15 2.17226 15 2.4484 15 3.00069",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:d(()=>[r[31]||(r[31]=I(" 复制提示词到大模型生成 ",-1))]),_:1}),m(p(G),{type:"primary",size:"small",class:"save-btn",disabled:!C.value,onClick:Ke},{icon:d(()=>[...r[32]||(r[32]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M5 13l4 4L19 7",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:d(()=>[r[33]||(r[33]=I(" 保存 (Ctrl+S) ",-1))]),_:1},8,["disabled"]),m(p(G),{type:"info",size:"small",class:"test-btn",loading:D.value,onClick:r[6]||(r[6]=y=>Y.value=!0)},{icon:d(()=>[...r[34]||(r[34]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("polygon",{points:"5 3 19 12 5 21 5 3",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:d(()=>[r[35]||(r[35]=I(" 测试执行 ",-1))]),_:1},8,["loading"])],2)])]),_:1})]),_:1},8,["value"])]),_:1},8,["model"])])]),_:1},8,["show"]),m(p(vt),{show:Y.value,"onUpdate:show":r[12]||(r[12]=y=>Y.value=y),preset:"card",bordered:!1,class:"test-args-modal",style:Mt({width:U.value?"800px":"600px"}),title:"测试执行参数"},{header:d(()=>[...r[37]||(r[37]=[o("div",{class:"modal-header"},[o("div",{class:"modal-icon"},[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("polygon",{points:"5 3 19 12 5 21 5 3",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})])]),o("div",null,[o("h3",{class:"modal-title"},"输入测试参数"),o("p",{class:"modal-subtitle"},'请输入 JSON 格式的参数(例如:{"param1": "value1", "param2": 123})')])],-1)])]),footer:d(()=>[o("div",ur,[m(p(G),{size:"large",onClick:lt},{default:d(()=>[...r[48]||(r[48]=[I("取消",-1)])]),_:1}),m(p(G),{type:"primary",size:"large",loading:D.value,onClick:xt},{default:d(()=>[...r[49]||(r[49]=[I(" 执行测试 ",-1)])]),_:1},8,["loading"])])]),default:d(()=>[o("div",Ks,[O.value.parameters&&O.value.parameters.length>0?(F(),q("div",Gs,[o("div",Ws,[r[38]||(r[38]=o("span",{class:"parameters-title"},"参数定义",-1)),o("span",Zs,ne(O.value.parameters.length)+" 个参数",1)]),m(p(Pt),{columns:Se,data:O.value.parameters.filter(y=>y.name&&y.name.trim()),pagination:!1,size:"small",bordered:"",class:"test-args-table"},null,8,["data"])])):ce("",!0),o("div",Qs,[o("div",Ys,[r[41]||(r[41]=o("span",{class:"test-args-input-title"},"测试参数 (JSON)",-1)),m(p(G),{size:"small",type:"default",onClick:at},{icon:d(()=>[(F(),q("svg",Xs,[...r[39]||(r[39]=[o("path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1),o("path",{d:"M21 3v5h-5",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1),o("path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1),o("path",{d:"M3 21v-5h5",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])]))]),default:d(()=>[r[40]||(r[40]=I(" 重置 ",-1))]),_:1})]),m(p(be),{value:H.value,"onUpdate:value":r[10]||(r[10]=y=>H.value=y),type:"textarea",placeholder:'{"param1": "value1", "param2": 123}',rows:8,autosize:{minRows:8,maxRows:12},class:"test-args-input"},null,8,["value"])]),U.value&&z.value?(F(),q("div",er,[o("div",tr,[o("div",or,[(F(),q("svg",nr,[...r[42]||(r[42]=[o("path",{d:"M9 11l3 3L22 4",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1),o("path",{d:"M21 12v7a2 2 0 01-2 2H5a2 2 0 01-2-2V5a2 2 0 012-2h11",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])])),r[43]||(r[43]=o("span",null,"测试结果",-1))]),o("div",sr,[m(p(G),{size:"small",text:"",onClick:Je},{icon:d(()=>[(F(),q("svg",rr,[...r[44]||(r[44]=[o("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1),o("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])]))]),default:d(()=>[r[45]||(r[45]=I(" 复制 ",-1))]),_:1}),m(p(G),{size:"small",text:"",onClick:r[11]||(r[11]=y=>U.value=!1)},{icon:d(()=>[(F(),q("svg",ar,[...r[46]||(r[46]=[o("path",{d:"M18 6L6 18M6 6l12 12",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])]))]),_:1})])]),o("div",lr,[o("pre",ir,[o("code",cr,ne(he(z.value)),1),r[47]||(r[47]=I(`
495
+ `,-1))])])])):ce("",!0)])]),_:1},8,["show","style"])]))}}),Sr=zt(dr,[["__scopeId","data-v-99a8719e"]]),pr={class:"init-script-editor"},vr={class:"save-status-indicator"},gr=["title"],mr={key:0,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},fr={key:1,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},hr={class:"monaco-wrapper"},yr={class:"editor-actions"},Ve=`/**
496
+ * MCP 初始化脚本
497
+ * 在 MCP 客户端连接时执行,用于环境检查、数据预加载等操作
498
+ */
499
+ export default async function(context: Context) {
500
+ const { log } = context;
501
+
502
+ log.info('🚀 MCP 环境初始化完成');
503
+
504
+ // 示例:检查变量配置
505
+ // const apiKey = context.vars.get('API_KEY');
506
+ // if (!apiKey) {
507
+ // log.warn('⚠️ API_KEY 未配置');
508
+ // }
509
+ }`,Ot="init-script-local-draft",wr=ht({__name:"InitScriptEditor",props:{config:{}},emits:["update"],setup(t,{emit:a}){const s=Dt(),c=t,u=a,h=A([]),j=A([]);async function k(){try{const l=await ue.get("/configs/all-tools");l.data.success&&l.data.data.tools?h.value=l.data.data.tools:h.value=[]}catch(l){console.error("Failed to load MCP tools from database:",l),h.value=[]}}async function $(){try{const l=await ue.get("/tables/definitions");l.data.success&&(j.value=l.data.data||[])}catch(l){console.error("Failed to load tables:",l),j.value=[]}}const P=Te(()=>so({config:c.config,mcpTools:h.value,tables:j.value})),R=Te(()=>[{content:P.value,filePath:"file:///init-script-context.d.ts"}]);At(()=>{k(),$()}),ke(()=>c.config.components,()=>{k()},{deep:!0}),ke(()=>c.config.customTools,()=>{k()},{deep:!0});function V(){try{return localStorage.getItem(Ot)||null}catch(l){return console.error("Failed to load local script:",l),null}}function D(l){try{localStorage.setItem(Ot,l)}catch(K){console.error("Failed to save to local storage:",K)}}function L(){try{localStorage.removeItem(Ot)}catch(l){console.error("Failed to clear local script:",l)}}const Y=V(),H=c.config.initScript||"",U=A(Y||H||Ve),C=A(H),B=A(Y||""),le=Te(()=>U.value!==B.value),J=Te(()=>B.value!==C.value),Z=A(!1),_=A(!1),ge=Te(()=>_.value?"height: 100%; border-radius: 12px; overflow: hidden;":"height: calc(100vh - 300px); min-height: 600px; max-height: 800px; border-radius: 12px; overflow: hidden;");ke(()=>c.config.initScript,(l,K)=>{const ee=l||"";if(ee===(K||""))return;const Pe=V();if(Pe&&ee===Pe){L(),B.value="",C.value=ee,U.value=ee;return}if(Pe&&ee!==Pe){L(),B.value="",C.value=ee;const Oe=ee||Ve;U.value=Oe;return}if(C.value=ee,!ee&&C.value)return;const _e=ee||Ve;U.value=_e,C.value=ee},{immediate:!0});function $e(l){}function me(){const l=U.value.trim()||"";D(l),B.value=l,s.success("已保存到本地 (Ctrl+S)")}async function we(){const l=B.value.trim()||void 0;u("update",{initScript:l}),C.value=l||"",L(),B.value=""}async function de(){var l,K;if(!U.value.trim()){s.warning("请先编写脚本内容");return}me(),Z.value=!0;try{const ee=await ue.post("/configs/test-init-script",{script:U.value});ee.data.success?s.success("测试执行成功,请查看服务端控制台输出"):s.error(`测试执行失败: ${ee.data.error}`)}catch(ee){s.error(`测试执行失败: ${((K=(l=ee.response)==null?void 0:l.data)==null?void 0:K.error)||ee.message}`)}finally{Z.value=!1}}function Be(){_.value=!_.value}function Ce(l){const K=l.match(/export\s+default\s+async\s+function\s*\([^)]*\)\s*\{([\s\S]*)\}/);return K&&K[1]?K[1].trim():l}async function Se(){try{const l=ro({config:c.config,mcpTools:h.value,tables:j.value}),K=U.value.trim()||Ve,ee=Ce(K),Ne=Ce(Ve),_e=ao({contextTypeDef:l,functionBody:ee,hasCustomImplementation:K!==Ve&&ee!==Ne,functionParams:"context"});await navigator.clipboard.writeText(_e),s.success("提示词已复制到剪贴板!")}catch(l){console.error("Failed to copy prompt:",l),s.error("复制失败,请手动复制")}}return(l,K)=>(F(),q("div",pr,[K[9]||(K[9]=Wt('<div class="editor-toolbar" data-v-ac356067><div class="toolbar-info" data-v-ac356067><svg class="info-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" data-v-ac356067><polyline points="16 18 22 12 16 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" data-v-ac356067></polyline><polyline points="8 6 2 12 8 18" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" data-v-ac356067></polyline></svg><span data-v-ac356067>初始化脚本在 MCP 连接时执行,用于初始化环境、加载数据等操作</span></div></div>',1)),o("div",{class:Ae(["editor-container",{fullscreen:_.value}])},[o("div",vr,[o("div",{class:Ae(["status-dot",{unsaved:le.value,saved:!le.value,"local-only":J.value&&!le.value}]),title:le.value?"未保存到本地":J.value?"已保存到本地,未上传":"已保存"},null,10,gr)]),m(p(G),{type:"default",size:"small",class:"fullscreen-btn",onClick:Be},{icon:d(()=>[_.value?(F(),q("svg",fr,[...K[2]||(K[2]=[o("path",{d:"M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 1 2-2h3M3 16h3a2 2 0 0 1 2 2v3",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])])):(F(),q("svg",mr,[...K[1]||(K[1]=[o("path",{d:"M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])]))]),default:d(()=>[I(" "+ne(_.value?"退出全屏":"全屏"),1)]),_:1}),o("div",hr,[m(ft,{modelValue:U.value,"onUpdate:modelValue":K[0]||(K[0]=ee=>U.value=ee),language:"typescript",options:{minimap:{enabled:!0},fontSize:14,lineHeight:22,padding:{top:16,bottom:16},scrollBeyondLastLine:!1,automaticLayout:!0},"extra-libs":R.value,onSave:me,onChange:$e,style:Mt(ge.value)},null,8,["modelValue","extra-libs","style"])]),o("div",yr,[m(p(G),{type:"default",size:"small",class:"copy-prompt-btn",onClick:Se},{icon:d(()=>[...K[3]||(K[3]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M8 5.00069C7.01165 5.00069 6.49359 5.00069 6.09202 5.21967C5.71569 5.42393 5.42413 5.71549 5.21987 6.09182C5 6.49339 5 7.01145 5 7.99979V15.9998C5 16.9881 5 17.5062 5.21987 17.9078C5.42413 18.2841 5.71569 18.5757 6.09202 18.7799C6.49359 18.9998 7.01165 18.9998 8 18.9998H16C16.9883 18.9998 17.5064 18.9998 17.908 18.7799C18.2843 18.5757 18.5759 18.2841 18.7801 17.9078C19 17.5062 19 16.9881 19 15.9998V7.99979C19 7.01145 19 6.49339 18.7801 6.09182C18.5759 5.71549 18.2843 5.42393 17.908 5.21967C17.5064 5.00069 16.9883 5.00069 16 5.00069H8Z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"}),o("path",{d:"M9 3.00069C9 2.4484 9 2.17226 9.08579 1.94418C9.18885 1.67761 9.37764 1.38893 9.58579 1.18378C9.79094 0.975636 10.0796 0.786849 10.3462 0.683785C10.5743 0.598 10.8504 0.598 11.4027 0.598H14.5973C15.1496 0.598 15.4257 0.598 15.6538 0.683785C15.9204 0.786849 16.2091 0.975636 16.4142 1.18378C16.6224 1.38893 16.8111 1.67761 16.9142 1.94418C17 2.17226 17 2.4484 17 3.00069V4.00069C17 4.55297 16.5523 5.00069 16 5.00069H8C7.44772 5.00069 7 4.55297 7 4.00069V3.00069C7 2.4484 7 2.17226 7.08579 1.94418C7.18885 1.67761 7.37764 1.38893 7.58579 1.18378C7.79094 0.975636 8.07963 0.786849 8.34621 0.683785C8.57428 0.598 8.85043 0.598 9.40272 0.598H12.5973C13.1496 0.598 13.4257 0.598 13.6538 0.683785C13.9204 0.786849 14.2091 0.975636 14.4142 1.18378C14.6224 1.38893 14.8111 1.67761 14.9142 1.94418C15 2.17226 15 2.4484 15 3.00069",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:d(()=>[K[4]||(K[4]=I(" 复制提示词到大模型生成 ",-1))]),_:1}),m(p(G),{type:"primary",size:"small",class:"upload-btn",disabled:!J.value,onClick:we},{icon:d(()=>[...K[5]||(K[5]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"}),o("polyline",{points:"17 8 12 3 7 8",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"}),o("line",{x1:"12",y1:"3",x2:"12",y2:"15",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:d(()=>[K[6]||(K[6]=I(" 上传脚本 ",-1))]),_:1},8,["disabled"]),m(p(G),{type:"info",size:"small",class:"test-btn",loading:Z.value,onClick:de},{icon:d(()=>[...K[7]||(K[7]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("polygon",{points:"5 3 19 12 5 21 5 3",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:d(()=>[K[8]||(K[8]=I(" 测试执行 ",-1))]),_:1},8,["loading"])])],2)]))}}),$r=zt(wr,[["__scopeId","data-v-ac356067"]]);export{Sr as C,$r as I,Tr as M,ft as _,Qe as g,xr as p,Cr as u};