flex-mcp 1.1.4 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/configs.js +12 -2
- package/dist/api/configs.js.map +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +135 -84
- package/dist/cli.js.map +1 -1
- package/dist/daemon.d.ts +25 -0
- package/dist/daemon.d.ts.map +1 -0
- package/dist/daemon.js +261 -0
- package/dist/daemon.js.map +1 -0
- package/dist/index.js +35 -2
- package/dist/index.js.map +1 -1
- package/dist/mcp/tool-sync.d.ts.map +1 -1
- package/dist/mcp/tool-sync.js +0 -1
- package/dist/mcp/tool-sync.js.map +1 -1
- package/dist/web/assets/{Blank-2vpGi200.js → Blank-BAn70pKV.js} +1 -1
- package/dist/web/assets/{Configs-4PrDyfwx.js → Configs-C6QxaALX.js} +1 -1
- package/dist/web/assets/{Dashboard-D8vYINT3.js → Dashboard-CC6Oo381.js} +2 -2
- package/dist/web/assets/InitScriptEditor-DzzTB5Qk.js +679 -0
- package/dist/web/assets/{Layout-CYzaFG4l.js → Layout-BOxnvITD.js} +1 -1
- package/dist/web/assets/{Layout-C5VF6KaE.js → Layout-CNq36nXL.js} +1 -1
- package/dist/web/assets/{Login-uQx8mYT4.js → Login-BxCS6qf-.js} +1 -1
- package/dist/web/assets/{Login-DEm7Yc0V.js → Login-zgQ_fCXm.js} +1 -1
- package/dist/web/assets/{Users-zZdxWL7h.js → Users-68dlwZ5K.js} +1 -1
- package/dist/web/assets/{index-NmCbGUEa.js → index-DAOSS2K-.js} +162 -162
- package/dist/web/assets/style-C2LUa6XO.css +1 -0
- package/dist/web/index.html +2 -2
- package/package.json +2 -1
- package/dist/web/assets/InitScriptEditor-RtEtxdk9.js +0 -679
- package/dist/web/assets/style-hUGligFl.css +0 -1
|
@@ -0,0 +1,679 @@
|
|
|
1
|
+
import{a1 as co,r as N,J as de,d as xt,I as Ut,U as po,A as Ce,c as R,o as _,u as Jt,p as Pe,m as ue,f as g,b as o,w as u,g as p,B as q,a2 as go,e as Xt,D as bt,h as E,F as ht,s as yt,y as _e,t as X,Q as st,Z as mo,a3 as vo,K as eo,L as rt,a4 as It,a5 as fo,a6 as Bt,a7 as Rt,N as to,j as ce,k as we,O as oo,a8 as Ot,M as Ve,x as Ee,E as no,a9 as Me,S as ho,aa as yo,l as vt,ab as wo,Y as bo,R as Le,C as At,ac as _t,n as ve,G as Vt,_ as Lt,ad as ko,H as xo}from"./index-DAOSS2K-.js";import{_ as Ft}from"./_plugin-vue_export-helper-DlAUqK2U.js";const Or=co("config",()=>{const t=N(null),l=N(!1);async function s(){var P,M;l.value=!0;try{const L=await de.get("/configs/me");return t.value=L.data.data,t.value}catch(L){throw new Error(((M=(P=L.response)==null?void 0:P.data)==null?void 0:M.error)||"Failed to fetch config")}finally{l.value=!1}}async function i(P){var M,L;l.value=!0;try{const V=await de.get(`/configs/user/${P}`);return t.value=V.data.data,t.value}catch(V){throw new Error(((L=(M=V.response)==null?void 0:M.data)==null?void 0:L.error)||"Failed to fetch user config")}finally{l.value=!1}}async function d(P){var M,L;l.value=!0;try{const V=await de.put("/configs/me",P);return t.value=V.data.data,t.value}catch(V){throw new Error(((L=(M=V.response)==null?void 0:M.data)==null?void 0:L.error)||"Failed to update config")}finally{l.value=!1}}async function w(P,M){var L,V;l.value=!0;try{const B=await de.put(`/configs/user/${P}`,M);return t.value=B.data.data,t.value}catch(B){throw new Error(((V=(L=B.response)==null?void 0:L.data)==null?void 0:V.error)||"Failed to update user config")}finally{l.value=!1}}function j(P){const M={...P,variables:P.variables.map(L=>({...L,value:L.isSecret?`{{${L.name}}}`:L.value}))};return JSON.stringify(M,null,2)}function T(P){try{const M=JSON.parse(P);if(!M.name||!Array.isArray(M.components)||!Array.isArray(M.customTools))throw new Error("Invalid config format");return M}catch(M){throw new Error(`Failed to parse config: ${M.message}`)}}return{currentConfig:t,loading:l,fetchConfig:s,fetchUserConfig:i,updateConfig:d,updateUserConfig:w,exportConfig:j,importConfig:T}});function ot(){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 qt(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 Co(t,l){let s=t;const i=/\{\{#if\s+(\w+)\}\}([\s\S]*?)(?:\{\{else\}\}([\s\S]*?))?\{\{\/if\}\}/g;s=s.replace(i,(w,j,T,P)=>{const M=l[j];return qt(M)?T||"":P||""});const d=/\{\{#ifnot\s+(\w+)\}\}([\s\S]*?)(?:\{\{else\}\}([\s\S]*?))?\{\{\/ifnot\}\}/g;return s=s.replace(d,(w,j,T,P)=>{const M=l[j];return qt(M)?P||"":T||""}),s}function To(t,l){return t.replace(/\{\{(\w+)\}\}/g,(s,i)=>{const d=l[i];return d!=null?String(d):s})}function Ar(t,l){let s=Co(t,l);return s=To(s,l),s}function Ht(t,l){(l==null||l>t.length)&&(l=t.length);for(var s=0,i=Array(l);s<l;s++)i[s]=t[s];return i}function So(t){if(Array.isArray(t))return t}function $o(t,l,s){return(l=Do(l))in t?Object.defineProperty(t,l,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[l]=s,t}function Po(t,l){var s=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(s!=null){var i,d,w,j,T=[],P=!0,M=!1;try{if(w=(s=s.call(t)).next,l!==0)for(;!(P=(i=w.call(s)).done)&&(T.push(i.value),T.length!==l);P=!0);}catch(L){M=!0,d=L}finally{try{if(!P&&s.return!=null&&(j=s.return(),Object(j)!==j))return}finally{if(M)throw d}}return T}}function jo(){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 Kt(t,l){var s=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);l&&(i=i.filter(function(d){return Object.getOwnPropertyDescriptor(t,d).enumerable})),s.push.apply(s,i)}return s}function Gt(t){for(var l=1;l<arguments.length;l++){var s=arguments[l]!=null?arguments[l]:{};l%2?Kt(Object(s),!0).forEach(function(i){$o(t,i,s[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(s)):Kt(Object(s)).forEach(function(i){Object.defineProperty(t,i,Object.getOwnPropertyDescriptor(s,i))})}return t}function No(t,l){if(t==null)return{};var s,i,d=Oo(t,l);if(Object.getOwnPropertySymbols){var w=Object.getOwnPropertySymbols(t);for(i=0;i<w.length;i++)s=w[i],l.indexOf(s)===-1&&{}.propertyIsEnumerable.call(t,s)&&(d[s]=t[s])}return d}function Oo(t,l){if(t==null)return{};var s={};for(var i in t)if({}.hasOwnProperty.call(t,i)){if(l.indexOf(i)!==-1)continue;s[i]=t[i]}return s}function Ao(t,l){return So(t)||Po(t,l)||zo(t,l)||jo()}function Mo(t,l){if(typeof t!="object"||!t)return t;var s=t[Symbol.toPrimitive];if(s!==void 0){var i=s.call(t,l);if(typeof i!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(l==="string"?String:Number)(t)}function Do(t){var l=Mo(t,"string");return typeof l=="symbol"?l:l+""}function zo(t,l){if(t){if(typeof t=="string")return Ht(t,l);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)?Ht(t,l):void 0}}function _o(t,l,s){return l in t?Object.defineProperty(t,l,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[l]=s,t}function Wt(t,l){var s=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);l&&(i=i.filter(function(d){return Object.getOwnPropertyDescriptor(t,d).enumerable})),s.push.apply(s,i)}return s}function Zt(t){for(var l=1;l<arguments.length;l++){var s=arguments[l]!=null?arguments[l]:{};l%2?Wt(Object(s),!0).forEach(function(i){_o(t,i,s[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(s)):Wt(Object(s)).forEach(function(i){Object.defineProperty(t,i,Object.getOwnPropertyDescriptor(s,i))})}return t}function Eo(){for(var t=arguments.length,l=new Array(t),s=0;s<t;s++)l[s]=arguments[s];return function(i){return l.reduceRight(function(d,w){return w(d)},i)}}function nt(t){return function l(){for(var s=this,i=arguments.length,d=new Array(i),w=0;w<i;w++)d[w]=arguments[w];return d.length>=t.length?t.apply(this,d):function(){for(var j=arguments.length,T=new Array(j),P=0;P<j;P++)T[P]=arguments[P];return l.apply(s,[].concat(d,T))}}}function kt(t){return{}.toString.call(t).includes("Object")}function Uo(t){return!Object.keys(t).length}function lt(t){return typeof t=="function"}function Jo(t,l){return Object.prototype.hasOwnProperty.call(t,l)}function Fo(t,l){return kt(l)||Je("changeType"),Object.keys(l).some(function(s){return!Jo(t,s)})&&Je("changeField"),l}function Io(t){lt(t)||Je("selectorType")}function Bo(t){lt(t)||kt(t)||Je("handlerType"),kt(t)&&Object.values(t).some(function(l){return!lt(l)})&&Je("handlersType")}function Ro(t){t||Je("initialIsRequired"),kt(t)||Je("initialType"),Uo(t)&&Je("initialContent")}function Vo(t,l){throw new Error(t[l]||t.default)}var Lo={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"},Je=nt(Vo)(Lo),ft={changes:Fo,selector:Io,handler:Bo,initial:Ro};function qo(t){var l=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};ft.initial(t),ft.handler(l);var s={current:t},i=nt(Go)(s,l),d=nt(Ko)(s),w=nt(ft.changes)(t),j=nt(Ho)(s);function T(){var M=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(L){return L};return ft.selector(M),M(s.current)}function P(M){Eo(i,d,w,j)(M)}return[T,P]}function Ho(t,l){return lt(l)?l(t.current):l}function Ko(t,l){return t.current=Zt(Zt({},t.current),l),l}function Go(t,l,s){return lt(l)?l(t.current):Object.keys(s).forEach(function(i){var d;return(d=l[i])===null||d===void 0?void 0:d.call(l,t.current[i])}),s}var Wo={create:qo},Zo={paths:{vs:"https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs"}};function Yo(t){return function l(){for(var s=this,i=arguments.length,d=new Array(i),w=0;w<i;w++)d[w]=arguments[w];return d.length>=t.length?t.apply(this,d):function(){for(var j=arguments.length,T=new Array(j),P=0;P<j;P++)T[P]=arguments[P];return l.apply(s,[].concat(d,T))}}}function Qo(t){return{}.toString.call(t).includes("Object")}function Xo(t){return t||Yt("configIsRequired"),Qo(t)||Yt("configType"),t.urls?(en(),{paths:{vs:t.urls.monacoBase}}):t}function en(){console.warn(so.deprecation)}function tn(t,l){throw new Error(t[l]||t.default)}var so={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
|
+
`},Yt=Yo(tn)(so),on={config:Xo},nn=function(){for(var l=arguments.length,s=new Array(l),i=0;i<l;i++)s[i]=arguments[i];return function(d){return s.reduceRight(function(w,j){return j(w)},d)}};function ro(t,l){return Object.keys(l).forEach(function(s){l[s]instanceof Object&&t[s]&&Object.assign(l[s],ro(t[s],l[s]))}),Gt(Gt({},t),l)}var sn={type:"cancelation",msg:"operation is manually canceled"};function Mt(t){var l=!1,s=new Promise(function(i,d){t.then(function(w){return l?d(sn):i(w)}),t.catch(d)});return s.cancel=function(){return l=!0},s}var rn=["monaco"],an=Wo.create({config:Zo,isInitialized:!1,resolve:null,reject:null,monaco:null}),ao=Ao(an,2),it=ao[0],Ct=ao[1];function ln(t){var l=on.config(t),s=l.monaco,i=No(l,rn);Ct(function(d){return{config:ro(d.config,i),monaco:s}})}function un(){var t=it(function(l){var s=l.monaco,i=l.isInitialized,d=l.resolve;return{monaco:s,isInitialized:i,resolve:d}});if(!t.isInitialized){if(Ct({isInitialized:!0}),t.monaco)return t.resolve(t.monaco),Mt(Dt);if(window.monaco&&window.monaco.editor)return lo(window.monaco),t.resolve(window.monaco),Mt(Dt);nn(cn,pn)(gn)}return Mt(Dt)}function cn(t){return document.body.appendChild(t)}function dn(t){var l=document.createElement("script");return t&&(l.src=t),l}function pn(t){var l=it(function(i){var d=i.config,w=i.reject;return{config:d,reject:w}}),s=dn("".concat(l.config.paths.vs,"/loader.js"));return s.onload=function(){return t()},s.onerror=l.reject,s}function gn(){var t=it(function(s){var i=s.config,d=s.resolve,w=s.reject;return{config:i,resolve:d,reject:w}}),l=window.require;l.config(t.config),l(["vs/editor/editor.main"],function(s){var i=s.m||s;lo(i),t.resolve(i)},function(s){t.reject(s)})}function lo(t){it().monaco||Ct({monaco:t})}function mn(){return it(function(t){var l=t.monaco;return l})}var Dt=new Promise(function(t,l){return Ct({resolve:t,reject:l})}),vn={config:ln,init:un,__getMonacoInstance:mn};const at=xt({__name:"MonacoEditor",props:{modelValue:{},language:{},theme:{},options:{},extraLibs:{}},emits:["update:modelValue","save","change"],setup(t,{emit:l}){const s=t,i=l,d=N();let w=null,j=null,T=null,P=!1,M=null;const L=N(new Map);function V(B){if(!j)return;L.value.forEach(K=>{K.dispose()}),L.value.clear();const ee=(s.language||"typescript")==="typescript"?j.languages.typescript.typescriptDefaults:j.languages.typescript.javascriptDefaults;ee.setDiagnosticsOptions({noSemanticValidation:!1,noSyntaxValidation:!1}),ee.setCompilerOptions({target:j.languages.typescript.ScriptTarget.ES2020,allowNonTsExtensions:!0,strict:!0}),ee.setInlayHintsOptions({includeInlayParameterNameHints:"all"}),B.forEach(K=>{const U=K.filePath||`file:///lib-${Date.now()}.d.ts`,I=ee.addExtraLib(K.content,U);L.value.set(U,I)})}return Ut(async()=>{var W,ee,K;j=await vn.init(),s.extraLibs&&V(s.extraLibs);const B=s.language||"typescript";T&&T.dispose(),T=j.languages.registerCompletionItemProvider(B,{provideCompletionItems:()=>({suggestions:[]}),triggerCharacters:['"',"'"]}),w=j.editor.create(d.value,{value:s.modelValue,language:B,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,...(W=s.options)==null?void 0:W.quickSuggestions},suggestOnTriggerCharacters:((ee=s.options)==null?void 0:ee.suggestOnTriggerCharacters)??!0,wordWrap:((K=s.options)==null?void 0:K.wordWrap)??"off"}),w.onDidChangeModelContent(U=>{var J;if(P)return;const I=w.getValue();i("update:modelValue",I),i("change",I);const x=(J=U.changes)==null?void 0:J[U.changes.length-1];x&&(x.text==='"'||x.text==="'")&&setTimeout(()=>{w&&w.trigger("","editor.action.triggerSuggest",{})},100)}),w.addCommand(j.KeyMod.CtrlCmd|j.KeyCode.KeyS,()=>{i("save")}),M=U=>{if(!(!w||!w.hasTextFocus())){if((U.metaKey||U.ctrlKey)&&U.key==="z"&&!U.shiftKey){U.preventDefault(),U.stopPropagation();const I=w.getModel();return I&&I.canUndo()&&I.undo(),!1}if((U.metaKey||U.ctrlKey)&&U.key==="z"&&U.shiftKey){U.preventDefault(),U.stopPropagation();const I=w.getModel();return I&&I.canRedo()&&I.redo(),!1}if((U.metaKey||U.ctrlKey)&&U.key==="y"){U.preventDefault(),U.stopPropagation();const I=w.getModel();return I&&I.canRedo()&&I.redo(),!1}}},document.addEventListener("keydown",M,!0)}),po(()=>{T==null||T.dispose(),w==null||w.dispose(),M&&(document.removeEventListener("keydown",M,!0),M=null)}),Ce(()=>s.modelValue,B=>{if(!w)return;if(w.getValue()!==B){P=!0;try{const ee=w.getModel();if(ee){const K=ee.getFullModelRange();w.executeEdits("external-update",[{range:K,text:B}]),w.pushUndoStop();const U=ee.getLineCount(),I=ee.getLineMaxColumn(U);w.setPosition({lineNumber:U,column:I})}}finally{setTimeout(()=>{P=!1},0)}}}),Ce(()=>s.extraLibs,(B,W)=>{if(!B||!j||!(!W||B.length!==W.length||B.some((U,I)=>{const x=W[I];return!x||U.content!==x.content||U.filePath!==x.filePath})))return;V(B);const K=w==null?void 0:w.getModel();K&&(j.editor.setModelMarkers(K,"typescript",[]),setTimeout(()=>{w&&K&&K.getValue()===K.getValue()&&K.forceTokenization(K.getLineCount())},100))},{deep:!0,immediate:!1}),(B,W)=>(_(),R("div",{ref_key:"editorContainer",ref:d,class:"w-full h-full min-h-[400px]"},null,512))}}),fn={class:"components-manager"},hn={key:0,class:"components-toolbar"},yn={class:"toolbar-actions"},wn={key:1},bn={class:"component-item"},kn={class:"component-main"},xn={class:"component-icon"},Cn={class:"icon-circle"},Tn={class:"component-info"},Sn={class:"component-title"},$n={class:"name"},Pn={class:"component-actions"},jn={key:0,class:"component-tools"},Nn={key:2,class:"empty-state"},On={class:"empty-state-content"},An={class:"empty-actions"},Mn={class:"modal-header"},Dn={class:"modal-title"},zn={class:"modal-subtitle"},_n={class:"modal-content-wrapper"},En={class:"tab-pane-content"},Un={class:"mode-switcher"},Jn={class:"form-content"},Fn={class:"form-section"},In={class:"form-grid"},Bn={key:0,class:"form-section"},Rn={class:"form-grid"},Vn={key:1,class:"form-section"},Ln={key:2,class:"form-section"},qn={class:"json-content"},Hn={class:"editor-wrapper"},Kn={class:"tab-pane-content tools-tab-content"},Gn={class:"tools-action-bar"},Wn={class:"tools-action-buttons"},Zn={key:0,class:"batch-actions"},Yn={key:0,class:"tools-list-wrapper"},Qn={class:"tools-list"},Xn=["onClick"],es={class:"tool-header"},ts={class:"tool-checkbox"},os={class:"tool-info"},ns=["title"],ss={class:"tooltip-description"},rs={class:"tool-actions"},as={class:"detail-section"},ls=["onDblclick"],is={key:2,class:"description-actions"},us={key:0,class:"detail-section"},cs={class:"params-list"},ds={class:"param-header"},ps={class:"param-name"},gs={key:0,class:"param-type"},ms={key:1,class:"param-required"},vs=["onDblclick"],fs={key:2,class:"field-description-actions"},hs={key:1,class:"detail-section"},ys={key:1,class:"tools-empty"},ws={key:2,class:"tools-error"},bs={class:"tab-pane-content"},ks={class:"schema-editor"},xs={class:"schema-tool-info"},Cs={class:"original-desc"},Ts={class:"schema-actions"},Ss={class:"modal-footer"},$s={style:{"font-size":"12px",color:"#666"}},Ps={key:0},js={class:"modal-footer"},Ns=xt({__name:"MCPComponentsManager",props:{config:{}},emits:["update"],setup(t,{emit:l}){const s=t,i=l,d=Jt(),w=N(!1),j=N("config"),T=N("form"),P=N(!1),M=N(!1),L=N(!1),V=N(!1),B=N(""),W=N(null),ee=N(),K=N(""),U=N(""),I=N({}),x=N(!1),J=N({current:0,total:0,currentComponent:""});function ie(c){j.value=c}const F=N([]),Y=N(new Set),D=N({}),fe=N(0),Ne=Pe(()=>{const c=r.value.toolPatches,e=D.value,n=F.value;fe.value;const h={};return n.forEach(m=>{var b;const y=be(m),$=c[y];$&&$.description!==void 0&&$.description!==null&&$.description!==""?h[m.name]=$.description:h[m.name]=((b=e[y])==null?void 0:b.description)||"暂无描述"}),h}),he=N(null),xe=N(null),pe=N(""),qe=N("tool"),Te=N(""),je=N(""),r=N({name:"",type:"npm",package:"",version:"",url:"",command:"",args:[],env:[],headers:[],disabledTools:[],toolPatches:{},namespace:"",extraConfig:{},rootExtra:{},configStr:"{}",disabled:!1}),H=[{label:"NPM 包",value:"npm"},{label:"Stdio (Command)",value:"stdio"},{label:"SSE (URL)",value:"url"}],te={name:{required:!0,message:"请输入名称",trigger:"blur"},type:{required:!0,message:"请选择类型",trigger:"change"}};function Oe(c){const e={};return c.forEach(n=>{n.key&&(e[n.key]=n.value)}),e}function Se(c){return c?Object.entries(c).map(([e,n])=>({key:e,value:n})):[]}function Ue(c,e){const n=[...s.config.components],h=n.findIndex(m=>m.id===c.id);h!==-1&&(n[h]={...c,disabled:!e},i("update",{components:n}))}function Ae(c){var A,se,ne;const e=(A=c.config)!=null&&A.headers?Se(c.config.headers):[],n=((se=c.config)==null?void 0:se.disabledTools)||[],h=(ne=c.config)!=null&&ne.toolPatches?JSON.parse(JSON.stringify(c.config.toolPatches)):{};console.log("加载时的 toolPatches:",JSON.stringify(h,null,2));const{headers:m,disabledTools:y,toolPatches:$,tools:C,...b}=c.config||{},oe=["id","name","type","namespace","env","package","version","url","command","args","config","disabled"],O={};Object.keys(c).forEach(z=>{oe.includes(z)||(O[z]=c[z])}),r.value={name:c.name||"",type:c.type||"npm",package:c.package||"",version:c.version||"",url:c.url||"",command:c.command||"",args:c.args||[],env:Se(c.env),headers:e,disabledTools:n,toolPatches:h,namespace:c.namespace||"",extraConfig:b,rootExtra:O,configStr:JSON.stringify(c,null,2),disabled:!!c.disabled}}function He(){const c={...r.value.rootExtra,name:r.value.name,type:r.value.type,namespace:r.value.namespace||void 0,env:r.value.env.length>0?Oe(r.value.env):void 0,disabled:r.value.disabled?!0:void 0};r.value.type==="npm"?(c.package=r.value.package,c.version=r.value.version||void 0):r.value.type==="url"?c.url=r.value.url:r.value.type==="stdio"&&(c.command=r.value.command,c.args=r.value.args);const e={...r.value.extraConfig};return e.disabledTools=r.value.disabledTools,r.value.headers.length>0&&(e.headers=Oe(r.value.headers)),F.value.length>0&&(e.tools=F.value),r.value.toolPatches&&Object.keys(r.value.toolPatches).length>0&&(e.toolPatches=JSON.parse(JSON.stringify(r.value.toolPatches))),Object.keys(e).length>0&&(c.config=e),JSON.parse(JSON.stringify(c))}Ce(T,c=>{var e;if(j.value==="config"){if(c==="json")try{const n=He();(e=W.value)!=null&&e.id&&(n.id=W.value.id),r.value.configStr=JSON.stringify(n,null,2)}catch(n){console.error(n)}else if(c==="form")try{const n=JSON.parse(r.value.configStr);Ae(n)}catch{d.error("JSON 格式错误,忽略更改")}}});async function S(c){var e;W.value=c,j.value="config",T.value="form",Ae(c),F.value=[],B.value="",Y.value.clear(),he.value=null,xe.value=null,pe.value="",D.value={},console.log("[editComponent] form.value.toolPatches after fillFormFromData:",JSON.stringify(r.value.toolPatches,null,2)),console.log("[editComponent] component.config?.toolPatches:",JSON.stringify((e=c.config)==null?void 0:e.toolPatches,null,2)),await Fe(c.id,!0),console.log("[editComponent] form.value.toolPatches after loadComponentTools:",JSON.stringify(r.value.toolPatches,null,2)),console.log("[editComponent] originalTools after loadComponentTools:",JSON.stringify(D.value,null,2)),w.value=!0}async function Fe(c,e=!1){var n,h,m,y,$,C,b,oe;try{const O=await de.get(`/configs/component-tools/${c}`);if(O.data.success&&O.data.data.tools&&O.data.data.tools.length>0){const A=s.config.components.find(k=>k.id===c),se=e?((n=A==null?void 0:A.config)==null?void 0:n.toolPatches)||{}:{},ne=Array.isArray((h=A==null?void 0:A.config)==null?void 0:h.disabledTools)?A.config.disabledTools:[],z={};F.value=O.data.data.tools.map(k=>{const Q=k.originalToolName||k.name;if(k.originalDescription!==void 0&&k.originalInputSchema!==void 0)z[Q]={description:k.originalDescription||"",inputSchema:JSON.parse(JSON.stringify(k.originalInputSchema||{type:"object",properties:{}}))};else{const ke=se[Q];ke&&ke.description!==void 0&&ke.description!==null&&ke.description!==""?(console.warn(`[loadComponentTools] 无法获取工具 ${Q} 的原始数据,因为后端 API 没有返回 originalDescription`),D.value[Q]?z[Q]=D.value[Q]:z[Q]={description:"",inputSchema:{type:"object",properties:{}}}):z[Q]={description:k.description||"",inputSchema:JSON.parse(JSON.stringify(k.inputSchema||{type:"object",properties:{}}))}}let me=k.inputSchema||{type:"object",properties:{}};if(e&&se[Q]){const ke=se[Q];ke.inputSchema&&(me={...me,...ke.inputSchema})}return{name:k.name,description:k.description||"",inputSchema:me,disabled:ne.includes(Q),originalToolName:Q}}),e&&Object.keys(D.value).forEach(k=>{z[k]||(z[k]=D.value[k])}),Object.keys(z).forEach(k=>{var Q;z[k].description===""&&((Q=D.value[k])!=null&&Q.description)&&(z[k]=D.value[k])}),D.value=z;const ae=r.value.toolPatches&&Object.keys(r.value.toolPatches).length>0?r.value.toolPatches:((m=A==null?void 0:A.config)==null?void 0:m.toolPatches)||{};console.log("[loadComponentTools] existingToolPatches:",JSON.stringify(ae,null,2)),console.log("[loadComponentTools] form.value.toolPatches:",JSON.stringify(r.value.toolPatches,null,2)),console.log("[loadComponentTools] component.config?.toolPatches:",JSON.stringify((y=A==null?void 0:A.config)==null?void 0:y.toolPatches,null,2));const G={},le=new Set(F.value.map(k=>k.originalToolName||k.name).filter(k=>k!=null&&k!==""));console.log("[loadComponentTools] currentToolNames:",Array.from(le)),console.log("[loadComponentTools] existingToolPatches keys:",Object.keys(ae)),Object.keys(ae).forEach(k=>{le.has(k)?(G[k]=ae[k],console.log(`[loadComponentTools] 保留 toolPatch: ${k}`)):console.log(`[loadComponentTools] 过滤掉 toolPatch: ${k} (不在当前工具列表中)`)}),A&&(e||Object.keys(G).length>0)&&(A.config?A.config.toolPatches=G:A.config={toolPatches:G}),r.value.toolPatches=JSON.parse(JSON.stringify(G)),console.log("[loadComponentTools] final form.value.toolPatches:",JSON.stringify(r.value.toolPatches,null,2)),console.log("[loadComponentTools] originalTools:",JSON.stringify(D.value,null,2));return}}catch(O){(($=O.response)==null?void 0:$.status)===404?console.log("数据库中没有工具列表,尝试从 MCP 组件加载"):console.warn("从数据库加载工具列表失败:",O)}try{const O=s.config.components.find(se=>se.id===c);if(!O){F.value=[];return}const A=await de.post("/configs/component-tools/load",{componentId:c});if(A.data.success&&A.data.data.tools){const se=e?((C=O.config)==null?void 0:C.toolPatches)||{}:{},ne=Array.isArray((b=O.config)==null?void 0:b.disabledTools)?O.config.disabledTools:[],z={};F.value=A.data.data.tools.map(k=>{const Q=k.originalToolName||(()=>{const ke=k.name.split("_");return ke.length>1?ke.slice(-1)[0]:k.name})();z[Q]={description:k.description||"",inputSchema:JSON.parse(JSON.stringify(k.inputSchema||{type:"object",properties:{}}))};let me=k.inputSchema||{type:"object",properties:{}};if(e&&se[Q]){const ke=se[Q];ke.inputSchema&&(me={...me,...ke.inputSchema})}return{name:k.name,description:k.description||"",inputSchema:me,disabled:ne.includes(Q),originalToolName:Q}}),e&&Object.keys(D.value).forEach(k=>{z[k]||(z[k]=D.value[k])}),D.value=z;const ae=r.value.toolPatches&&Object.keys(r.value.toolPatches).length>0?r.value.toolPatches:((oe=O.config)==null?void 0:oe.toolPatches)||{};console.log("[loadComponentTools-from-MCP] existingToolPatches:",JSON.stringify(ae,null,2));const G={},le=new Set(F.value.map(k=>k.originalToolName));Object.keys(ae).forEach(k=>{le.has(k)&&(G[k]=ae[k])}),e&&O&&(O.config?O.config.toolPatches=G:O.config={toolPatches:G}),r.value.toolPatches=JSON.parse(JSON.stringify(G)),console.log("[loadComponentTools-from-MCP] final form.value.toolPatches:",JSON.stringify(r.value.toolPatches,null,2)),console.log("[loadComponentTools-from-MCP] originalTools:",JSON.stringify(D.value,null,2))}else F.value=[]}catch(O){console.warn("从 MCP 组件加载工具列表失败:",O),F.value=[]}}function Ie(c){const e=s.config.components.filter(n=>n.id!==c);i("update",{components:e})}async function Tt(c){var e,n,h;I.value[c.id]=!0;try{const m=await de.post("/configs/sync-tools",{componentId:c.id});if(m.data.success)if(m.data.data.errors&&m.data.data.errors.length>0)d.error(`同步工具失败: ${m.data.data.errors.join("; ")}`);else if(m.data.data.success>0){d.success(`工具同步成功:${m.data.data.success} 个工具已更新`),m.data.data.failed>0&&d.warning(`${m.data.data.failed} 个工具同步失败`);try{const y=await de.get(`/configs/component-tools/${c.id}`);if(y.data.success&&y.data.data.tools){const $=y.data.data.tools.length,C=[...s.config.components],b=C.findIndex(oe=>oe.id===c.id);b!==-1&&(C[b]={...C[b],config:{...C[b].config,toolCount:$}},i("update",{components:C}))}}catch(y){console.warn("更新组件工具总数失败:",y)}((e=W.value)==null?void 0:e.id)===c.id&&await Fe(c.id,!0)}else d.warning("没有工具需要同步");else d.error(`同步工具失败: ${m.data.error||"未知错误"}`)}catch(m){d.error(`同步工具失败: ${((h=(n=m.response)==null?void 0:n.data)==null?void 0:h.error)||m.message}`)}finally{I.value[c.id]=!1}}async function ut(){var c,e;if(!W.value){d.warning("请先选择要编辑的组件");return}V.value=!0,B.value="";try{const n=await de.post("/configs/sync-tools",{componentId:W.value.id});n.data.success?n.data.data.errors&&n.data.data.errors.length>0?(B.value=n.data.data.errors.join("; "),d.error(`同步工具失败: ${B.value}`)):n.data.data.success>0?(d.success(`工具同步成功:${n.data.data.success} 个工具已更新`),n.data.data.failed>0&&(d.warning(`${n.data.data.failed} 个工具同步失败`),n.data.data.errors&&n.data.data.errors.length>0&&(B.value=n.data.data.errors.join("; "))),await Fe(W.value.id,!0)):d.warning("没有工具需要同步"):(B.value=n.data.error||"同步失败",d.error(`同步工具失败: ${B.value}`))}catch(n){B.value=((e=(c=n.response)==null?void 0:c.data)==null?void 0:e.error)||n.message,d.error(`同步工具失败: ${B.value}`)}finally{V.value=!1}}function ct(c){var n,h,m;const e=((n=c.config)==null?void 0:n.toolCount)??((m=(h=c.config)==null?void 0:h.tools)==null?void 0:m.length);return e!=null&&e>0?e:null}function dt(c){var h,m,y,$,C;const e=((h=c.config)==null?void 0:h.toolCount)??((y=(m=c.config)==null?void 0:m.tools)==null?void 0:y.length),n=((C=($=c.config)==null?void 0:$.disabledTools)==null?void 0:C.length)||0;if(e!=null&&e>0){const b=Math.max(0,e-n);return b>0?b:null}return null}function St(c){const e=c.originalToolName||c.name;return r.value.disabledTools.includes(e)}function $t(c,e){const n=c.originalToolName||c.name;e?r.value.disabledTools=r.value.disabledTools.filter(h=>h!==n):r.value.disabledTools.includes(n)||r.value.disabledTools.push(n)}function Qe(){r.value.disabledTools=[],d.success("已全选所有工具")}function Pt(){const c=F.value.map(n=>n.originalToolName||n.name),e=new Set(r.value.disabledTools);r.value.disabledTools=c.filter(n=>!e.has(n)),d.success("已反选工具")}function be(c){return c.originalToolName||c.name}function Ke(c){return Ne.value[c.name]||"暂无描述"}function pt(c,e,n){var O,A,se,ne;fe.value;const h=be(c),m=r.value.toolPatches,y=D.value,$=m[h],C=y[h],b=(O=$==null?void 0:$.fieldDescriptions)==null?void 0:O[e];return b!=null&&b!==""?b:((ne=(se=(A=C==null?void 0:C.inputSchema)==null?void 0:A.properties)==null?void 0:se[e])==null?void 0:ne.description)||"暂无描述"}function gt(c){var y;const e=be(c),n=r.value.toolPatches[e],h=n==null?void 0:n.description;if(h==null||h==="")return!1;const m=((y=D.value[e])==null?void 0:y.description)||c.description||"暂无描述";return console.log(`[hasCustomDescription] Tool ${e}:`,{hasCustomDescription:!!h,customDescription:h==null?void 0:h.trim(),originalDescription:m==null?void 0:m.trim(),areDifferent:(h==null?void 0:h.trim())!==(m==null?void 0:m.trim()),toolPatches:r.value.toolPatches[e],originalTools:D.value[e],formToolPatches:r.value.toolPatches,allOriginalTools:D.value,toolKey:e,toolName:c.name,toolOriginalToolName:c.originalToolName}),!D.value[e]&&h?(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 mt(c,e){var $,C,b,oe,O,A,se,ne,z,ae,G,le,k;const n=be(c),h=r.value.toolPatches[n],m=($=h==null?void 0:h.fieldDescriptions)==null?void 0:$[e];if(m==null||m==="")return!1;const y=((O=(oe=(b=(C=D.value[n])==null?void 0:C.inputSchema)==null?void 0:b.properties)==null?void 0:oe[e])==null?void 0:O.description)||((ne=(se=(A=c.inputSchema)==null?void 0:A.properties)==null?void 0:se[e])==null?void 0:ne.description)||"暂无描述";return console.log(`[hasCustomFieldDescription] Tool ${n}, Field ${e}:`,{hasCustomDescription:!!m,customDescription:m==null?void 0:m.trim(),originalDescription:y==null?void 0:y.trim(),areDifferent:(m==null?void 0:m.trim())!==(y==null?void 0:y.trim()),fieldPatches:(z=h==null?void 0:h.fieldDescriptions)==null?void 0:z[e],originalFieldDesc:(k=(le=(G=(ae=D.value[n])==null?void 0:ae.inputSchema)==null?void 0:G.properties)==null?void 0:le[e])==null?void 0:k.description,hasOriginalTool:!!D.value[n],toolKey:n,toolName:c.name,toolOriginalToolName:c.originalToolName}),!D.value[n]&&m?(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 Xe(c,e,n,h){var m,y,$,C,b,oe;if(e==="tool"){he.value=c,xe.value=null;const O=F.value.find(A=>A.name===c);pe.value=Ke(O),qe.value="tool",Te.value=be(O)}else{xe.value=c,he.value=null;const O=F.value.find(A=>A.name===n);if(O&&((y=(m=O.inputSchema)==null?void 0:m.properties)!=null&&y[h])){const A=O?be(O):"";(oe=(b=(C=($=D.value[A])==null?void 0:$.inputSchema)==null?void 0:C.properties)==null?void 0:b[h])!=null&&oe.description||O.inputSchema.properties[h].description,pe.value=pt(O,h)}else pe.value="";qe.value="field",Te.value=O?be(O):n||"",je.value=h||""}}function Ge(c,e,n,h){var m,y,$,C,b,oe,O,A,se;if(e==="tool"){const ne=F.value.find(le=>le.name===c),z=ne?be(ne):c,ae=((m=D.value[z])==null?void 0:m.description)||(ne==null?void 0:ne.description)||"暂无描述",G=pe.value.trim();G===ae.trim()||G===""?r.value.toolPatches[z]&&(delete r.value.toolPatches[z].description,Object.keys(r.value.toolPatches[z]).length===0&&delete r.value.toolPatches[z]):(r.value.toolPatches[z]||(r.value.toolPatches[z]={}),r.value.toolPatches[z].description=G),he.value=null,d.success("工具描述已保存")}else{const ne=F.value.find(k=>k.name===n),z=ne?be(ne):n||Te.value,ae=h||je.value,G=((b=(C=($=(y=D.value[z])==null?void 0:y.inputSchema)==null?void 0:$.properties)==null?void 0:C[ae])==null?void 0:b.description)||((A=(O=(oe=ne==null?void 0:ne.inputSchema)==null?void 0:oe.properties)==null?void 0:O[ae])==null?void 0:A.description)||"暂无描述",le=pe.value.trim();le===G.trim()||le===""?(se=r.value.toolPatches[z])!=null&&se.fieldDescriptions&&(delete r.value.toolPatches[z].fieldDescriptions[ae],Object.keys(r.value.toolPatches[z].fieldDescriptions).length===0&&delete r.value.toolPatches[z].fieldDescriptions,Object.keys(r.value.toolPatches[z]).length===0&&delete r.value.toolPatches[z]):(r.value.toolPatches[z]||(r.value.toolPatches[z]={}),r.value.toolPatches[z].fieldDescriptions||(r.value.toolPatches[z].fieldDescriptions={}),r.value.toolPatches[z].fieldDescriptions[ae]=le),xe.value=null,d.success("字段描述已保存")}pe.value="",Te.value="",je.value="",r.value.toolPatches=JSON.parse(JSON.stringify(r.value.toolPatches)),fe.value++,console.log("保存描述后的 toolPatches:",JSON.stringify(r.value.toolPatches,null,2)),Le(()=>{console.log("保存描述后 DOM 更新完成")})}function et(){he.value=null,xe.value=null,pe.value="",Te.value="",je.value=""}async function v(c,e,n,h){var m,y,$,C,b,oe,O,A,se,ne,z;if(e==="tool"){const ae=F.value.find(le=>le.name===c),G=ae?be(ae):c;if(r.value.toolPatches[G]){const le=r.value.toolPatches,k={};Object.keys(le).forEach(Q=>{if(Q!==G)k[Q]={...le[Q]};else{const me={...le[Q]};delete me.description,Object.keys(me).length>0&&(k[Q]=me)}}),r.value.toolPatches=k,fe.value++,console.log("[resetDescription-tool] 还原后的 toolPatches:",JSON.stringify(r.value.toolPatches,null,2)),console.log("[resetDescription-tool] toolKey:",G),console.log("[resetDescription-tool] 还原后的 patch:",r.value.toolPatches[G]),console.log("[resetDescription-tool] originalTools:",JSON.stringify(D.value[G],null,2)),console.log("[resetDescription-tool] toolDescriptionsMap 值:",Ne.value[ae.name]),d.success("工具描述已还原")}}else{const ae=F.value.find(k=>k.name===n),G=ae?be(ae):n||Te.value,le=h||je.value;if((m=r.value.toolPatches[G])!=null&&m.fieldDescriptions){const k=r.value.toolPatches,Q={};Object.keys(k).forEach(tt=>{if(tt!==G)Q[tt]={...k[tt]};else{const Re={...k[tt]};if(Re.fieldDescriptions){const jt={};Object.keys(Re.fieldDescriptions).forEach(Nt=>{Nt!==le&&(jt[Nt]=Re.fieldDescriptions[Nt])}),Object.keys(jt).length>0?Re.fieldDescriptions=jt:delete Re.fieldDescriptions}Object.keys(Re).length>0&&(Q[tt]=Re)}}),r.value.toolPatches=JSON.parse(JSON.stringify(Q)),fe.value++,console.log("[resetDescription-field] 还原后的 toolPatches:",JSON.stringify(r.value.toolPatches,null,2)),console.log("[resetDescription-field] actualToolKey:",G),console.log("[resetDescription-field] actualFieldName:",le),console.log("[resetDescription-field] 还原后的 patch:",r.value.toolPatches[G]),console.log("[resetDescription-field] 还原后的 patch.fieldDescriptions:",(y=r.value.toolPatches[G])==null?void 0:y.fieldDescriptions),console.log("[resetDescription-field] originalTools:",JSON.stringify(D.value[G],null,2)),console.log("[resetDescription-field] originalTools 字段描述:",(oe=(b=(C=($=D.value[G])==null?void 0:$.inputSchema)==null?void 0:C.properties)==null?void 0:b[le])==null?void 0:oe.description),await Le();const me=r.value.toolPatches[G],ke=(O=me==null?void 0:me.fieldDescriptions)==null?void 0:O[le],uo=((z=(ne=(se=(A=D.value[G])==null?void 0:A.inputSchema)==null?void 0:se.properties)==null?void 0:ne[le])==null?void 0:z.description)||"暂无描述";console.log("[resetDescription-field] 还原后的 patch.fieldDescriptions:",me==null?void 0:me.fieldDescriptions),console.log("[resetDescription-field] 字段描述是否已删除:",ke===void 0),console.log("[resetDescription-field] 期望的原始值:",uo),fe.value++,await Le(),d.success("字段描述已还原")}}pe.value="",Te.value="",je.value="",console.log("还原描述后的 toolPatches:",JSON.stringify(r.value.toolPatches,null,2)),console.log("还原描述后的 originalTools:",JSON.stringify(D.value,null,2)),Le(()=>{console.log("DOM 更新完成,descriptionUpdateKey:",fe.value)})}function a(c){Y.value.has(c)?Y.value.delete(c):(Y.value.clear(),Y.value.add(c))}const f=N(null),Z=N(""),re=N("{}");function $e(){if(f.value)try{const c=JSON.parse(re.value);r.value.toolPatches[f.value.name]||(r.value.toolPatches[f.value.name]={}),r.value.toolPatches[f.value.name].description=Z.value||void 0,r.value.toolPatches[f.value.name].inputSchema=c,d.success("Schema 修改已保存"),j.value="tools"}catch{d.error("JSON Schema 格式错误")}}async function ge(){var c,e,n,h;try{if(j.value==="config"&&T.value==="json")try{const C=JSON.parse(r.value.configStr||"{}");Ae(C)}catch{throw new Error("配置 JSON 格式错误")}if(await((c=ee.value)==null?void 0:c.validate()),M.value=!0,F.value.length===0)try{const C={id:((e=W.value)==null?void 0:e.id)||ot(),name:r.value.name,type:r.value.type,namespace:r.value.namespace,env:Oe(r.value.env),config:{headers:Oe(r.value.headers)}};r.value.type==="npm"?(C.package=r.value.package,C.version=r.value.version):r.value.type==="url"?C.url=r.value.url:r.value.type==="stdio"&&(C.command=r.value.command,C.args=r.value.args);const b=await de.post("/mcp/inspect",C);F.value=b.data.data.tools||[],F.value.length>0&&d.info(`自动获取到 ${F.value.length} 个工具`)}catch(C){console.warn("自动获取工具列表失败:",C)}console.log("保存前的 toolPatches:",JSON.stringify(r.value.toolPatches,null,2));const m=He();m.id=((n=W.value)==null?void 0:n.id)||ot(),console.log("保存的组件配置:",JSON.stringify(m,null,2)),console.log("组件 config.toolPatches:",JSON.stringify((h=m.config)==null?void 0:h.toolPatches,null,2));const y=[...s.config.components],$=y.findIndex(C=>C.id===m.id);$!==-1?y[$]=m:y.push(m),i("update",{components:y}),w.value=!1,Be()}catch(m){console.error("保存错误:",m),d.error(m.message)}finally{M.value=!1}}async function ye(){var c,e;x.value=!0,J.value={current:0,total:0,currentComponent:""};try{let n=[],h=[];if(K.value.trim()){const y=JSON.parse(K.value).mcpServers||{};h=Object.entries(y),J.value.total=h.length;for(let $=0;$<h.length;$++){const[C,b]=h[$];J.value.current=$+1,J.value.currentComponent=C;const oe=!!b.url,O={headers:b.headers,disabledTools:b.disabledTools,toolPatches:b.toolPatches};b.transportType&&(O.transportType=b.transportType),b.type&&(O.type=b.type);const A={id:ot(),name:C,type:oe?"url":"stdio",url:b.url,command:b.command,args:b.args||[],env:b.env,config:O};try{const se={...A,config:{headers:b.headers||{}}},z=(await de.post("/mcp/inspect",se)).data.data.tools||[];z.length>0&&(O.tools=z,A.config=O,console.log(`[导入] 组件 ${C} 解析到 ${z.length} 个工具`))}catch(se){console.warn(`[导入] 组件 ${C} 获取工具列表失败:`,se)}n.push(A)}}else if(U.value.trim()){const m=JSON.parse(U.value),y=Array.isArray(m)?m:m.components;J.value.total=y.length;for(let $=0;$<y.length;$++){const C=y[$];J.value.current=$+1,J.value.currentComponent=C.name||`组件 ${$+1}`;const b={...C,id:ot()};if(!((c=b.config)!=null&&c.tools)&&(b.url||b.command||b.package))try{const oe={...b,config:{...b.config,headers:((e=b.config)==null?void 0:e.headers)||{}}},A=(await de.post("/mcp/inspect",oe)).data.data.tools||[];A.length>0&&(b.config||(b.config={}),b.config.tools=A,console.log(`[导入] 组件 ${b.name} 解析到 ${A.length} 个工具`))}catch(oe){console.warn(`[导入] 组件 ${b.name} 获取工具列表失败:`,oe)}n.push(b)}}else throw new Error("请输入 JSON 内容");if(i("update",{components:[...s.config.components,...n]}),await new Promise(m=>setTimeout(m,800)),n.length>0){J.value.total=n.length,J.value.current=0;let m=0,y=0;for(let $=0;$<n.length;$++){const C=n[$];J.value.current=$+1,J.value.currentComponent=`正在同步工具: ${C.name}`;try{const b=await de.post("/configs/sync-tools",{componentId:C.id});b.data.success?b.data.data.errors&&b.data.data.errors.length>0?(y++,console.warn(`[导入] 组件 ${C.name} 同步工具失败:`,b.data.data.errors.join("; "))):b.data.data.success>0&&(m++,console.log(`[导入] 组件 ${C.name} 同步了 ${b.data.data.success} 个工具`)):(y++,console.warn(`[导入] 组件 ${C.name} 同步工具失败:`,b.data.error))}catch(b){y++,console.warn(`[导入] 组件 ${C.name} 同步工具失败:`,b.message||b)}}m>0?d.success(`导入成功:${n.length} 个组件已添加,${m} 个组件的工具已同步`):y>0?d.warning(`导入完成:${n.length} 个组件已添加,但工具同步失败`):d.success(`导入成功:${n.length} 个组件已添加`)}P.value=!1,K.value="",U.value=""}catch(n){d.error(`导入失败: ${n.message}`)}finally{x.value=!1,J.value={current:0,total:0,currentComponent:""}}}function ze(){const c={};s.config.components.forEach(y=>{var C,b,oe;const $={env:y.env};if(y.type==="url")$.url=y.url,(C=y.config)!=null&&C.headers&&($.headers=y.config.headers);else{let O=y.command,A=y.args||[];y.type==="npm"&&(O="npx",A=["-y",y.package],y.version&&y.version!=="latest"&&(A[1]=`${y.package}@${y.version}`)),$.command=O,$.args=A}(b=y.config)!=null&&b.disabledTools&&($.disabledTools=y.config.disabledTools),(oe=y.config)!=null&&oe.toolPatches&&($.toolPatches=y.config.toolPatches),c[y.name]=$});const e=JSON.stringify({mcpServers:c},null,2),n=new Blob([e],{type:"application/json"}),h=URL.createObjectURL(n),m=document.createElement("a");m.href=h,m.download="cursor-mcp.json",m.click(),URL.revokeObjectURL(h),d.success("已导出 Cursor 格式配置")}function Be(){W.value=null,r.value={name:"",type:"npm",package:"",version:"",url:"",command:"",args:[],env:[],headers:[],disabledTools:[],toolPatches:{},namespace:"",extraConfig:{},rootExtra:{},configStr:"{}",disabled:!1},j.value="config",T.value="form",F.value=[],B.value="",he.value=null,xe.value=null,pe.value="",Te.value="",je.value=""}return Ce(()=>w.value,c=>{c||Be()}),(c,e)=>(_(),R("div",fn,[t.config.components&&t.config.components.length>0?(_(),R("div",hn,[g(p(q),{type:"primary",size:"large",class:"add-component-btn",onClick:e[0]||(e[0]=n=>w.value=!0)},{icon:u(()=>[...e[31]||(e[31]=[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:u(()=>[e[32]||(e[32]=E(" 添加组件 ",-1))]),_:1}),o("div",yn,[g(p(q),{size:"large",class:"secondary-btn",onClick:e[1]||(e[1]=n=>P.value=!0)},{icon:u(()=>[...e[33]||(e[33]=[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:u(()=>[e[34]||(e[34]=E(" 导入 JSON ",-1))]),_:1}),g(p(q),{size:"large",class:"secondary-btn",onClick:ze},{icon:u(()=>[...e[35]||(e[35]=[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:u(()=>[e[36]||(e[36]=E(" 导出配置 ",-1))]),_:1})])])):ue("",!0),t.config.components&&t.config.components.length>0?(_(),R("div",wn,[g(p(go),{class:"component-list","show-divider":!1},{default:u(()=>[(_(!0),R(ht,null,yt(t.config.components,n=>(_(),_e(p(vo),{key:n.id},{default:u(()=>[o("div",bn,[o("div",kn,[o("div",xn,[o("div",Cn,X(n.name.charAt(0).toUpperCase()),1)]),o("div",Tn,[o("div",Sn,[o("span",$n,X(n.name),1),n.namespace&&n.namespace.trim()!==""?(_(),_e(p(st),{key:0,size:"small",type:"warning",style:{"margin-left":"8px"}},{default:u(()=>[E(" 命名空间:"+X(n.namespace.trim()),1)]),_:2},1024)):ue("",!0),ct(n)!==null?(_(),_e(p(st),{key:1,size:"small",type:"info"},{default:u(()=>[E(X(ct(n))+" 工具 ",1)]),_:2},1024)):ue("",!0),dt(n)!==null?(_(),_e(p(st),{key:2,size:"small",type:"success"},{default:u(()=>[E(X(dt(n))+" 可调用 ",1)]),_:2},1024)):ue("",!0)])]),o("div",Pn,[g(p(mo),{size:"small",value:!n.disabled,"onUpdate:value":h=>Ue(n,h)},{checked:u(()=>[...e[37]||(e[37]=[E("启用",-1)])]),unchecked:u(()=>[...e[38]||(e[38]=[E("禁用",-1)])]),_:1},8,["value","onUpdate:value"]),g(p(q),{size:"small",loading:I.value[n.id],onClick:h=>Tt(n),title:"同步工具配置"},{icon:u(()=>[...e[39]||(e[39]=[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:u(()=>[e[40]||(e[40]=E(" 同步工具 ",-1))]),_:1},8,["loading","onClick"]),g(p(q),{size:"small",onClick:h=>S(n)},{default:u(()=>[...e[41]||(e[41]=[E("配置",-1)])]),_:1},8,["onClick"]),g(p(q),{size:"small",type:"error",ghost:"",onClick:h=>Ie(n.id)},{default:u(()=>[...e[42]||(e[42]=[E("移除",-1)])]),_:1},8,["onClick"])])]),n.config?(_(),R("div",jn)):ue("",!0)])]),_:2},1024))),128))]),_:1})])):(_(),R("div",Nn,[o("div",On,[e[47]||(e[47]=Xt('<div class="empty-icon" data-v-9cddf37a><svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" data-v-9cddf37a><path d="M12 2L2 7l10 5 10-5-10-5z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" data-v-9cddf37a></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-9cddf37a></path></svg></div><h3 class="empty-title" data-v-9cddf37a>还没有添加 MCP 组件</h3><p class="empty-description" data-v-9cddf37a>点击上方"添加组件"按钮开始添加你的第一个 MCP 组件,或者使用"导入 JSON"快速导入配置</p>',3)),o("div",An,[g(p(q),{type:"primary",size:"large",onClick:e[2]||(e[2]=n=>w.value=!0)},{icon:u(()=>[...e[43]||(e[43]=[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:u(()=>[e[44]||(e[44]=E(" 添加组件 ",-1))]),_:1}),g(p(q),{size:"large",onClick:e[3]||(e[3]=n=>P.value=!0)},{icon:u(()=>[...e[45]||(e[45]=[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:u(()=>[e[46]||(e[46]=E(" 导入 JSON ",-1))]),_:1})])])])),g(p(bt),{show:w.value,"onUpdate:show":e[27]||(e[27]=n=>w.value=n),preset:"card",bordered:!1,class:"component-edit-modal",style:{width:"90vw",maxWidth:"1400px",height:"90vh",maxHeight:"90vh"}},{header:u(()=>[o("div",Mn,[e[48]||(e[48]=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",Dn,X(W.value?"配置 MCP 组件":"添加 MCP 组件"),1),o("p",zn,X(W.value?"修改组件配置和工具设置":"创建新的 MCP 服务组件"),1)])])]),footer:u(()=>[o("div",Ss,[g(p(q),{size:"large",onClick:e[26]||(e[26]=n=>w.value=!1)},{default:u(()=>[...e[79]||(e[79]=[E("取消",-1)])]),_:1}),g(p(q),{type:"primary",size:"large",onClick:ge},{default:u(()=>[E(X(W.value?"保存修改":"添加组件"),1)]),_:1})])]),default:u(()=>[o("div",_n,[g(p(eo),{value:j.value,"onUpdate:value":[e[25]||(e[25]=n=>j.value=n),ie],type:"line",animated:"",size:"large",class:"component-config-tabs"},{default:u(()=>[g(p(rt),{name:"config",tab:"基础配置"},{default:u(()=>[o("div",En,[o("div",Un,[g(p(fo),{value:T.value,"onUpdate:value":e[4]||(e[4]=n=>T.value=n),size:"medium"},{default:u(()=>[g(p(Bt),{value:"form"},{default:u(()=>[...e[49]||(e[49]=[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}),g(p(Bt),{value:"json"},{default:u(()=>[...e[50]||(e[50]=[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"])]),It(o("div",Jn,[g(p(to),{ref_key:"formRef",ref:ee,model:r.value,rules:te,"label-placement":"top",size:"large"},{default:u(()=>[o("div",Fn,[e[54]||(e[54]=o("h4",{class:"section-title"},"基础信息",-1)),o("div",In,[g(p(ce),{path:"name"},{label:u(()=>[...e[51]||(e[51]=[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:u(()=>[g(p(we),{value:r.value.name,"onUpdate:value":e[5]||(e[5]=n=>r.value.name=n),placeholder:"例如: filesystem, github"},null,8,["value"])]),_:1}),g(p(ce),{path:"type"},{label:u(()=>[...e[52]||(e[52]=[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:u(()=>[g(p(oo),{value:r.value.type,"onUpdate:value":e[6]||(e[6]=n=>r.value.type=n),options:H},null,8,["value"])]),_:1}),g(p(ce),{path:"namespace"},{label:u(()=>[...e[53]||(e[53]=[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:u(()=>[g(p(we),{value:r.value.namespace,"onUpdate:value":e[7]||(e[7]=n=>r.value.namespace=n),placeholder:"用于工具名前缀"},null,8,["value"])]),_:1})])]),r.value.type==="npm"?(_(),R("div",Bn,[e[55]||(e[55]=o("h4",{class:"section-title"},"NPM 配置",-1)),o("div",Rn,[g(p(ce),{path:"package",label:"NPM 包名",class:"col-span-2"},{default:u(()=>[g(p(we),{value:r.value.package,"onUpdate:value":e[8]||(e[8]=n=>r.value.package=n),placeholder:"@modelcontextprotocol/server-filesystem"},null,8,["value"])]),_:1}),g(p(ce),{path:"version",label:"版本"},{default:u(()=>[g(p(we),{value:r.value.version,"onUpdate:value":e[9]||(e[9]=n=>r.value.version=n),placeholder:"latest"},null,8,["value"])]),_:1})])])):ue("",!0),r.value.type==="url"?(_(),R("div",Vn,[e[56]||(e[56]=o("h4",{class:"section-title"},"URL 配置",-1)),g(p(ce),{path:"url",label:"服务地址"},{default:u(()=>[g(p(we),{value:r.value.url,"onUpdate:value":e[10]||(e[10]=n=>r.value.url=n),placeholder:"http://localhost:3000/mcp"},null,8,["value"])]),_:1}),g(p(ce),{label:"HTTP Headers"},{default:u(()=>[g(p(Ot),{value:r.value.headers,"onUpdate:value":e[11]||(e[11]=n=>r.value.headers=n),preset:"pair","key-placeholder":"Header 名称","value-placeholder":"Header 值"},null,8,["value"])]),_:1})])):ue("",!0),r.value.type==="stdio"?(_(),R("div",Ln,[e[57]||(e[57]=o("h4",{class:"section-title"},"Stdio 配置",-1)),g(p(ce),{path:"command",label:"执行命令"},{default:u(()=>[g(p(we),{value:r.value.command,"onUpdate:value":e[12]||(e[12]=n=>r.value.command=n),placeholder:"node, python, uvx"},null,8,["value"])]),_:1}),g(p(ce),{label:"命令行参数"},{default:u(()=>[g(p(Ot),{value:r.value.args,"onUpdate:value":e[13]||(e[13]=n=>r.value.args=n),placeholder:"输入参数",min:0},null,8,["value"])]),_:1}),g(p(ce),{label:"环境变量"},{default:u(()=>[g(p(Ot),{value:r.value.env,"onUpdate:value":e[14]||(e[14]=n=>r.value.env=n),preset:"pair","key-placeholder":"变量名","value-placeholder":"变量值"},null,8,["value"])]),_:1})])):ue("",!0)]),_:1},8,["model"])],512),[[Rt,T.value==="form"]]),It(o("div",qn,[g(p(Ve),{type:"info",bordered:!1,class:"json-alert"},{icon:u(()=>[...e[58]||(e[58]=[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:u(()=>[e[59]||(e[59]=E(" 直接编辑组件的完整 JSON 配置,切换回表单模式或保存时会自动同步 ",-1))]),_:1}),o("div",Hn,[g(at,{modelValue:r.value.configStr,"onUpdate:modelValue":e[15]||(e[15]=n=>r.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),[[Rt,T.value==="json"]])])]),_:1}),g(p(rt),{name:"tools",tab:"工具管理"},{default:u(()=>[o("div",Kn,[o("div",Gn,[g(p(Ve),{type:"info",bordered:!1,class:"tools-info-alert"},{icon:u(()=>[...e[60]||(e[60]=[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:u(()=>[e[61]||(e[61]=E(' 工具列表来自已保存的配置。您可以禁用特定工具或编辑其 Schema。点击"同步工具"可从 MCP 组件更新工具列表。双击工具描述或字段描述可进行编辑。 ',-1))]),_:1}),o("div",Wn,[g(p(q),{type:"primary",size:"large",loading:V.value,onClick:ut,class:"sync-btn"},{icon:u(()=>[...e[62]||(e[62]=[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:u(()=>[E(" "+X(V.value?"同步中...":"同步工具配置"),1)]),_:1},8,["loading"]),F.value.length>0?(_(),R("div",Zn,[g(p(q),{size:"medium",onClick:Qe,class:"batch-btn"},{default:u(()=>[...e[63]||(e[63]=[E(" 全选 ",-1)])]),_:1}),g(p(q),{size:"medium",onClick:Pt,class:"batch-btn"},{default:u(()=>[...e[64]||(e[64]=[E(" 反选 ",-1)])]),_:1})])):ue("",!0)])]),F.value.length>0?(_(),R("div",Yn,[o("div",Qn,[(_(!0),R(ht,null,yt(F.value,n=>(_(),R("div",{key:n.name,class:Ee(["tool-card",{"tool-expanded":Y.value.has(n.name)}]),onClick:h=>a(n.name)},[o("div",es,[o("div",ts,[g(p(no),{checked:!St(n),onClick:e[16]||(e[16]=Me(()=>{},["stop"])),"onUpdate:checked":h=>$t(n,h),size:"large"},null,8,["checked","onUpdate:checked"])]),o("div",os,[g(p(ho),{trigger:"hover","show-arrow":!0,placement:"top"},{trigger:u(()=>[o("h5",{class:"tool-name",title:Ke(n)},X(n.originalToolName||n.name),9,ns)]),default:u(()=>[o("div",ss,X(Ke(n)),1)]),_:2},1024)]),o("div",rs,[o("div",{class:Ee(["expand-icon",{expanded:Y.value.has(n.name)}])},[...e[65]||(e[65]=[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)])]),g(p(yo),{show:Y.value.has(n.name)},{default:u(()=>{var h;return[o("div",{class:"tool-details",onClick:e[21]||(e[21]=Me(()=>{},["stop"]))},[o("div",as,[o("div",{class:Ee(["detail-content",{"has-custom-description":gt(n)}])},[he.value!==n.name?(_(),R("div",{onDblclick:Me(m=>Xe(n.name,"tool"),["stop"]),class:"description-text-editable",key:`tool-desc-${n.name}-${fe.value}`},X(Ke(n)),41,ls)):(_(),_e(p(we),{key:1,value:pe.value,"onUpdate:value":e[17]||(e[17]=m=>pe.value=m),type:"textarea",rows:3,onBlur:m=>Ge(n.name,"tool"),onKeydown:[vt(Me(m=>Ge(n.name,"tool"),["ctrl"]),["enter"]),vt(et,["esc"])],class:"description-input",placeholder:"输入工具描述",onClick:e[18]||(e[18]=Me(()=>{},["stop"]))},null,8,["value","onBlur","onKeydown"])),gt(n)&&he.value!==n.name?(_(),R("div",is,[e[67]||(e[67]=o("span",{class:"custom-badge",title:"已自定义描述"},"已修改",-1)),g(p(q),{text:"",size:"small",onClick:Me(m=>v(n.name,"tool"),["stop"]),class:"reset-btn"},{default:u(()=>[...e[66]||(e[66]=[E(" 还原 ",-1)])]),_:1},8,["onClick"])])):ue("",!0)],2)]),(h=n.inputSchema)!=null&&h.properties&&Object.keys(n.inputSchema.properties).length>0?(_(),R("div",us,[e[70]||(e[70]=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",cs,[(_(!0),R(ht,null,yt(n.inputSchema.properties,(m,y)=>{var $;return _(),R("div",{key:String(y),class:"param-item"},[o("div",ds,[o("span",ps,X(y),1),m.type?(_(),R("span",gs,X(m.type),1)):ue("",!0),($=n.inputSchema.required)!=null&&$.includes(String(y))?(_(),R("span",ms,"必填")):ue("",!0)]),o("div",{class:Ee(["param-description-wrapper",{"has-custom-description":mt(n,String(y))}])},[xe.value!==`${n.name}.${String(y)}`?(_(),R("div",{class:"param-description",onDblclick:Me(C=>Xe(`${n.name}.${String(y)}`,"field",n.name,String(y)),["stop"]),key:`field-desc-${n.name}-${String(y)}-${fe.value}`},X(pt(n,String(y),m.description)),41,vs)):(_(),_e(p(we),{key:1,value:pe.value,"onUpdate:value":e[19]||(e[19]=C=>pe.value=C),type:"textarea",rows:2,onBlur:C=>Ge(`${n.name}.${String(y)}`,"field",n.name,String(y)),onKeydown:[vt(Me(C=>Ge(`${n.name}.${String(y)}`,"field",n.name,String(y)),["ctrl"]),["enter"]),vt(et,["esc"])],class:"description-input",placeholder:"输入字段描述",onClick:e[20]||(e[20]=Me(()=>{},["stop"]))},null,8,["value","onBlur","onKeydown"])),mt(n,String(y))&&xe.value!==`${n.name}.${String(y)}`?(_(),R("div",fs,[e[69]||(e[69]=o("span",{class:"custom-badge",title:"已自定义描述"},"已修改",-1)),g(p(q),{text:"",size:"small",onClick:Me(C=>v(`${n.name}.${String(y)}`,"field",n.name,String(y)),["stop"]),class:"reset-btn"},{default:u(()=>[...e[68]||(e[68]=[E(" 还原 ",-1)])]),_:1},8,["onClick"])])):ue("",!0)],2)])}),128))])])):(_(),R("div",hs,[...e[71]||(e[71]=[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,Xn))),128))])])):L.value?ue("",!0):(_(),R("div",ys,[...e[72]||(e[72]=[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)])])),B.value?(_(),R("div",ws,[g(p(Ve),{type:"error",bordered:!1},{icon:u(()=>[...e[73]||(e[73]=[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:u(()=>[...e[74]||(e[74]=[E("连接失败",-1)])]),default:u(()=>[E(" "+X(B.value),1)]),_:1})])):ue("",!0)])]),_:1}),j.value==="schema"?(_(),_e(p(rt),{key:0,name:"schema",tab:"Schema 编辑","display-directive":"show"},{default:u(()=>{var n,h;return[o("div",bs,[g(p(Ve),{type:"info",bordered:!1,class:"schema-info-alert"},{icon:u(()=>[...e[75]||(e[75]=[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:u(()=>[e[76]||(e[76]=E(" 重写工具的提示词。留空表示使用原始描述。修改后将覆盖工具的默认提示词 ",-1))]),_:1}),o("div",ks,[o("div",xs,[o("h4",null,X((n=f.value)==null?void 0:n.name),1),o("p",Cs,"原始描述: "+X((h=f.value)==null?void 0:h.description),1)]),g(p(ce),{label:"工具名称"},{default:u(()=>{var m;return[g(p(we),{value:(m=f.value)==null?void 0:m.name,disabled:""},null,8,["value"])]}),_:1}),g(p(ce),{label:"自定义描述"},{default:u(()=>[g(p(we),{value:Z.value,"onUpdate:value":e[22]||(e[22]=m=>Z.value=m),type:"textarea",rows:4,placeholder:"输入自定义描述(留空使用原始描述)"},null,8,["value"])]),_:1}),g(p(ce),{label:"完整 Schema (JSON)"},{default:u(()=>[g(at,{modelValue:re.value,"onUpdate:modelValue":e[23]||(e[23]=m=>re.value=m),language:"json",options:{minimap:{enabled:!1},fontSize:14,lineHeight:22,padding:{top:16,bottom:16}},style:{"min-height":"300px","border-radius":"12px",overflow:"hidden"}},null,8,["modelValue"])]),_:1}),o("div",Ts,[g(p(q),{onClick:e[24]||(e[24]=m=>j.value="tools"),size:"large"},{default:u(()=>[...e[77]||(e[77]=[E("取消",-1)])]),_:1}),g(p(q),{type:"primary",onClick:$e,size:"large"},{default:u(()=>[...e[78]||(e[78]=[E(" 保存 Schema ",-1)])]),_:1})])])])]}),_:1})):ue("",!0)]),_:1},8,["value"])])]),_:1},8,["show"]),g(p(bt),{show:P.value,"onUpdate:show":e[30]||(e[30]=n=>P.value=n),preset:"card",title:"导入组件 JSON",bordered:!1,class:"import-modal",style:{width:"800px",maxWidth:"90vw"}},{footer:u(()=>[o("div",js,[g(p(q),{size:"large",onClick:e[29]||(e[29]=n=>P.value=!1),disabled:x.value},{default:u(()=>[...e[83]||(e[83]=[E("取消",-1)])]),_:1},8,["disabled"]),g(p(q),{type:"primary",size:"large",onClick:ye,loading:x.value},{default:u(()=>[E(X(x.value?`导入中... (${J.value.current}/${J.value.total})`:"导入"),1)]),_:1},8,["loading"])])]),default:u(()=>[g(p(Ve),{type:"info",bordered:!1,style:{"margin-bottom":"20px"}},{icon:u(()=>[...e[80]||(e[80]=[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:u(()=>[e[81]||(e[81]=E(" 粘贴 Cursor MCP 配置的 JSON(mcpServers 对象) ",-1))]),_:1}),x.value?(_(),_e(p(Ve),{key:0,type:"info",bordered:!1,style:{"margin-bottom":"20px"}},{icon:u(()=>[g(p(bo),{size:"small"})]),default:u(()=>[o("div",null,[e[82]||(e[82]=o("div",{style:{"margin-bottom":"8px"}},[o("strong",null,"正在导入组件...")],-1)),o("div",$s,[E(X(J.value.currentComponent)+" ",1),J.value.total>0?(_(),R("span",Ps," ("+X(J.value.current)+"/"+X(J.value.total)+") ",1)):ue("",!0)]),J.value.total>0?(_(),_e(p(wo),{key:0,percentage:Math.round(J.value.current/J.value.total*100),"show-indicator":!1,style:{"margin-top":"8px"}},null,8,["percentage"])):ue("",!0)])]),_:1})):ue("",!0),g(at,{modelValue:K.value,"onUpdate:modelValue":e[28]||(e[28]=n=>K.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"])]))}}),Mr=Ft(Ns,[["__scopeId","data-v-9cddf37a"]]);function wt(t){return!t||typeof t!="string"?"Unknown":t.split(/[^a-zA-Z0-9_$]+/).filter(s=>s.length>0).map(s=>s.split("_").filter(i=>i.length>0).map(i=>i.charAt(0).toUpperCase()+i.slice(1).toLowerCase()).join("")).join("")||"Unknown"}function Qt(t){return wt(t)}function De(t){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(t)?`"${t}"`:`"${t.replace(/"/g,'\\"')}"`}function io(t){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(t)?t:`"${t.replace(/"/g,'\\"')}"`}function Ye(t,l="",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<${Ye(t.items,l,s+1)}>`:"any[]";case"object":if(t.properties){const i=[],d=Array.isArray(t.required)?t.required:[];for(const[w,j]of Object.entries(t.properties))try{const T=j,P=io(w),L=d.includes(w)?"":"?",V=Ye(T,l+" ",s+1),B=T&&typeof T=="object"&&T.description?`/** ${String(T.description).replace(/\*\//g,"* /")} */
|
|
12
|
+
${l} `:"";i.push(`${B}${P}${L}: ${V};`)}catch(T){console.warn(`Failed to process property ${w}:`,T)}return i.length===0?"Record<string, any>":`{
|
|
13
|
+
${l} ${i.join(`
|
|
14
|
+
${l} `)}
|
|
15
|
+
${l}}`}return"Record<string, any>";default:return"any"}if(t.anyOf&&Array.isArray(t.anyOf)){const i=t.anyOf.map(d=>Ye(d,l,s+1)).filter(d=>d&&d!=="any");return i.length>0?i.join(" | "):"any"}if(t.oneOf&&Array.isArray(t.oneOf)){const i=t.oneOf.map(d=>Ye(d,l,s+1)).filter(d=>d&&d!=="any");return i.length>0?i.join(" | "):"any"}if(t.allOf&&Array.isArray(t.allOf)){const i={type:"object",properties:{},required:[]};for(const d of t.allOf)d&&typeof d=="object"&&d.properties&&(i.properties={...i.properties,...d.properties}),d&&typeof d=="object"&&Array.isArray(d.required)&&(i.required=[...i.required||[],...d.required]);return Ye(i,l,s+1)}return Array.isArray(t.enum)?t.enum.map(i=>typeof i=="string"?De(i):JSON.stringify(i)).join(" | "):"any"}catch(i){return console.warn("Error converting JSON Schema to TypeScript:",i,t),"any"}}function Et(t){try{const{config:l,mcpTools:s=[],tables:i=[]}=t,d=l.variables.length>0?`type VarName = ${l.variables.map(x=>De(x.name)).join(" | ")};
|
|
16
|
+
|
|
17
|
+
`:"",w=i.map(x=>{const ie=`${wt(x.name)}TableRow`,F=x.columns.map(Y=>{const D=io(Y.name),Ne={string:"string",number:"number",boolean:"boolean",date:"string",json:"any"}[Y.type]||"any",he=Y.nullable?`${Ne} | null`:Ne,xe=Y.nullable?"?":"";return` ${D}${xe}: ${he};`}).join(`
|
|
18
|
+
`);return`type ${ie} = {
|
|
19
|
+
${F}
|
|
20
|
+
};
|
|
21
|
+
`}).join(`
|
|
22
|
+
`),j=i.length>0?`type TableName = ${i.map(x=>De(x.name)).join(" | ")};
|
|
23
|
+
|
|
24
|
+
`:"",T=s.length>0?`type ToolName = ${s.map(x=>{const J=x.originalToolName||x.name;return De(J)}).join(" | ")};
|
|
25
|
+
|
|
26
|
+
`:"",P=new Map;s.filter(x=>x&&x.name).forEach(x=>{try{const J=x.name||"Unknown",ie=Ye(x.inputSchema||{type:"object",properties:{}}),F=Qt(J);if(!F||F.trim()===""){console.warn(`[Context Types] Invalid type name for tool: ${J}`);return}const Y=`${F}Args`;if(!P.has(Y))P.set(Y,`type ${Y} = ${ie};`);else{const D=P.get(Y);D&&D!==`type ${Y} = ${ie};`&&console.warn(`[Context Types] Type ${Y} already exists with different definition for tool: ${J}`)}}catch(J){console.warn(`[Context Types] Failed to generate type for tool ${x==null?void 0:x.name}:`,J)}});const M=Array.from(P.values()).join(`
|
|
27
|
+
`),L=M?`${M}
|
|
28
|
+
|
|
29
|
+
`:"",V=s.filter(x=>x&&x.name).map(x=>{try{const J=x.originalToolName||x.name,ie=De(J),F=x.name||"Unknown",Y=Qt(F);if(!Y||Y.trim()==="")return console.warn(`[Context Types] Invalid type name for tool: ${F}, skipping overload`),null;const D=`${Y}Args`;return P.has(D)||console.warn(`[Context Types] Type ${D} not found in type definitions for tool: ${F}`),`${x.description?` /**
|
|
30
|
+
* ${x.description.replace(/\*\//g,"* /")}
|
|
31
|
+
*
|
|
32
|
+
* @param toolName - 工具名称(原始名称,不带命名空间)
|
|
33
|
+
* @param args - 工具参数
|
|
34
|
+
* @returns 工具执行结果
|
|
35
|
+
*/
|
|
36
|
+
`:" "}callTool(toolName: ${ie}, args: ${D}): Promise<any>;`}catch(J){return console.warn(`Failed to generate overload for tool ${x==null?void 0:x.name}:`,J),null}}).filter(x=>x!==null).join(`
|
|
37
|
+
`),B=s.length>0?`${V}
|
|
38
|
+
/**
|
|
39
|
+
* 调用 MCP 工具
|
|
40
|
+
*
|
|
41
|
+
* @param toolName - 工具名称
|
|
42
|
+
* @param args - 工具参数
|
|
43
|
+
* @returns 工具执行结果
|
|
44
|
+
*/
|
|
45
|
+
callTool(toolName: ToolName, args: any): Promise<any>;`:`/**
|
|
46
|
+
* 调用 MCP 工具
|
|
47
|
+
*
|
|
48
|
+
* @param toolName - 工具名称
|
|
49
|
+
* @param args - 工具参数
|
|
50
|
+
* @returns 工具执行结果
|
|
51
|
+
*/
|
|
52
|
+
callTool(toolName: string, args: any): Promise<any>;`,W=l.variables.length>0?"get(name: VarName): string;":"get(name: string): string;",ee=i.map(x=>{const ie=`${wt(x.name)}TableRow`;return` /**
|
|
53
|
+
* 获取指定表的所有数据行
|
|
54
|
+
*
|
|
55
|
+
* @param tableName - 表名
|
|
56
|
+
* @returns 返回该表的所有数据行数组,每行是一个包含列数据的对象
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* // 获取 users 表的所有数据
|
|
60
|
+
* const allUsers = await context.tables.get('users');
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* // 遍历所有用户
|
|
64
|
+
* const users = await context.tables.get('users');
|
|
65
|
+
* for (const user of users) {
|
|
66
|
+
* console.log(user.name, user.email);
|
|
67
|
+
* }
|
|
68
|
+
*/
|
|
69
|
+
get(tableName: ${De(x.name)}): Promise<Array<${ie}>>;`}).join(`
|
|
70
|
+
`),K=i.length>0?`${ee}
|
|
71
|
+
/**
|
|
72
|
+
* 获取指定表的所有数据行
|
|
73
|
+
*
|
|
74
|
+
* @param tableName - 表名
|
|
75
|
+
* @returns 返回该表的所有数据行数组,每行是一个包含列数据的对象
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* // 获取 users 表的所有数据
|
|
79
|
+
* const allUsers = await context.tables.get('users');
|
|
80
|
+
*/
|
|
81
|
+
get(tableName: TableName): Promise<Array<Record<string, any>>>;`:`/**
|
|
82
|
+
* 获取指定表的所有数据行
|
|
83
|
+
*
|
|
84
|
+
* @param tableName - 表名
|
|
85
|
+
* @returns 返回该表的所有数据行数组,每行是一个包含列数据的对象
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* // 获取 users 表的所有数据
|
|
89
|
+
* const allUsers = await context.tables.get('users');
|
|
90
|
+
*/
|
|
91
|
+
get(tableName: string): Promise<Array<Record<string, any>>>;`,U=i.map(x=>{const ie=`${wt(x.name)}TableRow`;return` /**
|
|
92
|
+
* 查询指定表的数据,支持使用过滤函数筛选行
|
|
93
|
+
*
|
|
94
|
+
* @param tableName - 表名
|
|
95
|
+
* @param filter - 可选的过滤函数,接收一行数据作为参数,返回 true 表示保留该行
|
|
96
|
+
* @returns 返回符合过滤条件的数据行数组
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* // 查询所有年龄大于 18 的用户
|
|
100
|
+
* const adults = await context.tables.query('users', (row) => row.age > 18);
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* // 查询所有活跃用户
|
|
104
|
+
* const activeUsers = await context.tables.query('users', (row) => row.isActive === true);
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* // 不传过滤函数,等同于 get(),返回所有数据
|
|
108
|
+
* const allUsers = await context.tables.query('users');
|
|
109
|
+
*/
|
|
110
|
+
query(tableName: ${De(x.name)}, filter?: (row: ${ie}) => boolean): Promise<Array<${ie}>>;`}).join(`
|
|
111
|
+
`),I=i.length>0?`${U}
|
|
112
|
+
/**
|
|
113
|
+
* 查询指定表的数据,支持使用过滤函数筛选行
|
|
114
|
+
*
|
|
115
|
+
* @param tableName - 表名
|
|
116
|
+
* @param filter - 可选的过滤函数,接收一行数据作为参数,返回 true 表示保留该行
|
|
117
|
+
* @returns 返回符合过滤条件的数据行数组
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* // 查询所有年龄大于 18 的用户
|
|
121
|
+
* const adults = await context.tables.query('users', (row) => row.age > 18);
|
|
122
|
+
*/
|
|
123
|
+
query(tableName: TableName, filter?: (row: Record<string, any>) => boolean): Promise<Array<Record<string, any>>>;`:`/**
|
|
124
|
+
* 查询指定表的数据,支持使用过滤函数筛选行
|
|
125
|
+
*
|
|
126
|
+
* @param tableName - 表名
|
|
127
|
+
* @param filter - 可选的过滤函数,接收一行数据作为参数,返回 true 表示保留该行
|
|
128
|
+
* @returns 返回符合过滤条件的数据行数组
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* // 查询所有年龄大于 18 的用户
|
|
132
|
+
* const adults = await context.tables.query('users', (row) => row.age > 18);
|
|
133
|
+
*/
|
|
134
|
+
query(tableName: string, filter?: (row: Record<string, any>) => boolean): Promise<Array<Record<string, any>>>;`;return`
|
|
135
|
+
${d}${w}${j}${L}${T}declare interface Context {
|
|
136
|
+
user: {
|
|
137
|
+
id: string;
|
|
138
|
+
email: string;
|
|
139
|
+
role: 'admin' | 'user';
|
|
140
|
+
createdAt: Date;
|
|
141
|
+
updatedAt: Date;
|
|
142
|
+
};
|
|
143
|
+
http: {
|
|
144
|
+
get(url: string, options?: any): Promise<any>;
|
|
145
|
+
post(url: string, data?: any, options?: any): Promise<any>;
|
|
146
|
+
put(url: string, data?: any, options?: any): Promise<any>;
|
|
147
|
+
delete(url: string, options?: any): Promise<any>;
|
|
148
|
+
};
|
|
149
|
+
fs: {
|
|
150
|
+
readFile(path: string): Promise<string>;
|
|
151
|
+
writeFile(path: string, content: string): Promise<void>;
|
|
152
|
+
exists(path: string): Promise<boolean>;
|
|
153
|
+
listDir(path: string): Promise<string[]>;
|
|
154
|
+
mkdir(path: string): Promise<void>;
|
|
155
|
+
};
|
|
156
|
+
cmd: {
|
|
157
|
+
exec(command: string, options?: { cwd?: string; timeout?: number }): Promise<{ stdout: string; stderr: string; exitCode: number }>;
|
|
158
|
+
};
|
|
159
|
+
utils: {
|
|
160
|
+
md5(input: string): string;
|
|
161
|
+
};
|
|
162
|
+
ripgrep: {
|
|
163
|
+
/**
|
|
164
|
+
* 搜索文件内容
|
|
165
|
+
*/
|
|
166
|
+
search(
|
|
167
|
+
pattern: string,
|
|
168
|
+
options?: {
|
|
169
|
+
/** 工作目录(相对于用户隔离目录) */
|
|
170
|
+
cwd?: string;
|
|
171
|
+
/** 是否大小写敏感 */
|
|
172
|
+
caseSensitive?: boolean;
|
|
173
|
+
/** 是否启用多行匹配 */
|
|
174
|
+
multiline?: boolean;
|
|
175
|
+
/** 文件过滤模式(glob 模式数组) */
|
|
176
|
+
files?: string[];
|
|
177
|
+
/** 排除文件模式(glob 模式数组) */
|
|
178
|
+
excludeFiles?: string[];
|
|
179
|
+
/** 每个文件的最大匹配数 */
|
|
180
|
+
maxCount?: number;
|
|
181
|
+
/** 总结果数的最大限制 */
|
|
182
|
+
maxResults?: number;
|
|
183
|
+
/** 最大递归深度 */
|
|
184
|
+
maxDepth?: number;
|
|
185
|
+
/** 匹配行之前显示的行数 */
|
|
186
|
+
contextBefore?: number;
|
|
187
|
+
/** 匹配行之后显示的行数 */
|
|
188
|
+
contextAfter?: number;
|
|
189
|
+
/** 匹配行前后显示的行数(等同于同时设置 contextBefore 和 contextAfter) */
|
|
190
|
+
context?: number;
|
|
191
|
+
/** 将模式视为固定字符串而非正则表达式 */
|
|
192
|
+
fixedStrings?: boolean;
|
|
193
|
+
/** 只匹配完整的单词 */
|
|
194
|
+
wordRegexp?: boolean;
|
|
195
|
+
/** 文件类型过滤(如:['js', 'ts']) */
|
|
196
|
+
fileTypes?: string[];
|
|
197
|
+
/** 排除的文件类型 */
|
|
198
|
+
excludeTypes?: string[];
|
|
199
|
+
/** 只返回包含匹配的文件名 */
|
|
200
|
+
filesWithMatches?: boolean;
|
|
201
|
+
/** 只返回每个文件的匹配数量 */
|
|
202
|
+
count?: boolean;
|
|
203
|
+
/** 忽略 .gitignore 和 .ignore 文件 */
|
|
204
|
+
noIgnore?: boolean;
|
|
205
|
+
/** 智能大小写:如果模式包含大写字母则大小写敏感 */
|
|
206
|
+
smartCase?: boolean;
|
|
207
|
+
}
|
|
208
|
+
): Promise<Array<{ file: string; line: number; text: string; column?: number; contextBefore?: string[]; contextAfter?: string[] }>>;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* 通过文件名模式搜索文件
|
|
212
|
+
*/
|
|
213
|
+
searchByPath(
|
|
214
|
+
pattern: string,
|
|
215
|
+
options?: {
|
|
216
|
+
/** 工作目录(相对于用户隔离目录) */
|
|
217
|
+
cwd?: string;
|
|
218
|
+
/** 是否大小写敏感 */
|
|
219
|
+
caseSensitive?: boolean;
|
|
220
|
+
/** 最大递归深度 */
|
|
221
|
+
maxDepth?: number;
|
|
222
|
+
/** 文件类型过滤(如:['js', 'ts']) */
|
|
223
|
+
fileTypes?: string[];
|
|
224
|
+
/** 排除的文件类型 */
|
|
225
|
+
excludeTypes?: string[];
|
|
226
|
+
/** 排除文件模式(glob 模式数组) */
|
|
227
|
+
excludeFiles?: string[];
|
|
228
|
+
/** 总结果数的最大限制 */
|
|
229
|
+
maxResults?: number;
|
|
230
|
+
/** 忽略 .gitignore 和 .ignore 文件 */
|
|
231
|
+
noIgnore?: boolean;
|
|
232
|
+
}
|
|
233
|
+
): Promise<string[]>;
|
|
234
|
+
};
|
|
235
|
+
mcp: {
|
|
236
|
+
${B}
|
|
237
|
+
listTools(): Promise<string[]>;
|
|
238
|
+
};
|
|
239
|
+
vars: {
|
|
240
|
+
${W}
|
|
241
|
+
has(name: string): boolean;
|
|
242
|
+
getAll(): Record<string, string>;
|
|
243
|
+
set(name: string, value: string, description?: string): void;
|
|
244
|
+
};
|
|
245
|
+
log: {
|
|
246
|
+
info(message: string, ...args: any[]): void;
|
|
247
|
+
error(message: string, ...args: any[]): void;
|
|
248
|
+
warn(message: string, ...args: any[]): void;
|
|
249
|
+
debug(message: string, ...args: any[]): void;
|
|
250
|
+
};
|
|
251
|
+
tables: {
|
|
252
|
+
/**
|
|
253
|
+
* 列出当前用户的所有表定义
|
|
254
|
+
*
|
|
255
|
+
* @returns 返回表定义数组,每个表定义包含:
|
|
256
|
+
* - id: 表的唯一标识符
|
|
257
|
+
* - name: 表名
|
|
258
|
+
* - description: 表的描述(可选)
|
|
259
|
+
* - columns: 列定义数组,每个列包含 name(列名)、type(类型)、nullable(是否可为空)
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* // 获取所有表定义
|
|
263
|
+
* const tables = await context.tables.list();
|
|
264
|
+
* console.log('共有', tables.length, '张表');
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* // 遍历所有表并打印表名和列信息
|
|
268
|
+
* const tables = await context.tables.list();
|
|
269
|
+
* for (const table of tables) {
|
|
270
|
+
* console.log('表名:', table.name);
|
|
271
|
+
* console.log('列数:', table.columns.length);
|
|
272
|
+
* table.columns.forEach(col => {
|
|
273
|
+
* console.log(' -', col.name + ':', col.type + (col.nullable ? ' (可为空)' : ''));
|
|
274
|
+
* });
|
|
275
|
+
* }
|
|
276
|
+
*/
|
|
277
|
+
list(): Promise<Array<{ id: string; name: string; description?: string; columns: Array<{ name: string; type: string; nullable: boolean }> }>>;
|
|
278
|
+
${K}
|
|
279
|
+
${I}
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
`}catch(l){return console.error("Error generating context type definition:",l),`
|
|
283
|
+
declare interface Context {
|
|
284
|
+
user: {
|
|
285
|
+
id: string;
|
|
286
|
+
email: string;
|
|
287
|
+
role: 'admin' | 'user';
|
|
288
|
+
createdAt: Date;
|
|
289
|
+
updatedAt: Date;
|
|
290
|
+
};
|
|
291
|
+
http: {
|
|
292
|
+
get(url: string, options?: any): Promise<any>;
|
|
293
|
+
post(url: string, data?: any, options?: any): Promise<any>;
|
|
294
|
+
put(url: string, data?: any, options?: any): Promise<any>;
|
|
295
|
+
delete(url: string, options?: any): Promise<any>;
|
|
296
|
+
};
|
|
297
|
+
fs: {
|
|
298
|
+
readFile(path: string): Promise<string>;
|
|
299
|
+
writeFile(path: string, content: string): Promise<void>;
|
|
300
|
+
exists(path: string): Promise<boolean>;
|
|
301
|
+
listDir(path: string): Promise<string[]>;
|
|
302
|
+
mkdir(path: string): Promise<void>;
|
|
303
|
+
};
|
|
304
|
+
cmd: {
|
|
305
|
+
exec(command: string, options?: { cwd?: string; timeout?: number }): Promise<{ stdout: string; stderr: string; exitCode: number }>;
|
|
306
|
+
};
|
|
307
|
+
utils: {
|
|
308
|
+
md5(input: string): string;
|
|
309
|
+
};
|
|
310
|
+
mcp: {
|
|
311
|
+
callTool(toolName: string, args: any): Promise<any>;
|
|
312
|
+
listTools(): Promise<string[]>;
|
|
313
|
+
};
|
|
314
|
+
vars: {
|
|
315
|
+
get(name: string): string;
|
|
316
|
+
has(name: string): boolean;
|
|
317
|
+
getAll(): Record<string, string>;
|
|
318
|
+
set(name: string, value: string, description?: string): void;
|
|
319
|
+
};
|
|
320
|
+
log: {
|
|
321
|
+
info(message: string, ...args: any[]): void;
|
|
322
|
+
error(message: string, ...args: any[]): void;
|
|
323
|
+
warn(message: string, ...args: any[]): void;
|
|
324
|
+
debug(message: string, ...args: any[]): void;
|
|
325
|
+
};
|
|
326
|
+
tables: {
|
|
327
|
+
list(): Promise<Array<{ id: string; name: string; description?: string; columns: Array<{ name: string; type: string; nullable: boolean }> }>>;
|
|
328
|
+
get(tableName: string): Promise<Array<Record<string, any>>>;
|
|
329
|
+
query(tableName: string, filter?: (row: Record<string, any>) => boolean): Promise<Array<Record<string, any>>>;
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
`}}function Os(t){try{const{config:l,mcpTools:s=[],tables:i=[]}=t,d=l.variables.length>0?`type VarName = ${l.variables.map(V=>De(V.name)).join(" | ")};
|
|
333
|
+
|
|
334
|
+
`:"",w=i.length>0?`type TableName = ${i.map(V=>De(V.name)).join(" | ")};
|
|
335
|
+
|
|
336
|
+
`:"",j=s.length>0?`type ToolName = ${s.map(V=>{const B=V.originalToolName||V.name;return De(B)}).join(" | ")};
|
|
337
|
+
|
|
338
|
+
`:"",T=l.variables.length>0?"get(name: VarName): string;":"get(name: string): string;",P=i.length>0?"get(tableName: TableName): Promise<Array<Record<string, any>>>;":"get(tableName: string): Promise<Array<Record<string, any>>>;",M=i.length>0?"query(tableName: TableName, 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>>>;",L=s.length>0?"callTool(toolName: ToolName, args: any): Promise<any>;":"callTool(toolName: string, args: any): Promise<any>;";return`
|
|
339
|
+
${d}${w}${j}declare interface Context {
|
|
340
|
+
user: {
|
|
341
|
+
id: string;
|
|
342
|
+
email: string;
|
|
343
|
+
role: 'admin' | 'user';
|
|
344
|
+
createdAt: Date;
|
|
345
|
+
updatedAt: Date;
|
|
346
|
+
};
|
|
347
|
+
http: {
|
|
348
|
+
get(url: string, options?: any): Promise<any>;
|
|
349
|
+
post(url: string, data?: any, options?: any): Promise<any>;
|
|
350
|
+
put(url: string, data?: any, options?: any): Promise<any>;
|
|
351
|
+
delete(url: string, options?: any): Promise<any>;
|
|
352
|
+
};
|
|
353
|
+
fs: {
|
|
354
|
+
readFile(path: string): Promise<string>;
|
|
355
|
+
writeFile(path: string, content: string): Promise<void>;
|
|
356
|
+
exists(path: string): Promise<boolean>;
|
|
357
|
+
listDir(path: string): Promise<string[]>;
|
|
358
|
+
mkdir(path: string): Promise<void>;
|
|
359
|
+
};
|
|
360
|
+
cmd: {
|
|
361
|
+
exec(command: string, options?: { cwd?: string; timeout?: number }): Promise<{ stdout: string; stderr: string; exitCode: number }>;
|
|
362
|
+
};
|
|
363
|
+
utils: {
|
|
364
|
+
md5(input: string): string;
|
|
365
|
+
};
|
|
366
|
+
ripgrep: {
|
|
367
|
+
search(pattern: string, options?: any): Promise<Array<{ file: string; line: number; text: string; column?: number; contextBefore?: string[]; contextAfter?: string[] }>>;
|
|
368
|
+
searchByPath(pattern: string, options?: any): Promise<string[]>;
|
|
369
|
+
};
|
|
370
|
+
mcp: {
|
|
371
|
+
${L}
|
|
372
|
+
listTools(): Promise<string[]>;
|
|
373
|
+
};
|
|
374
|
+
vars: {
|
|
375
|
+
${T}
|
|
376
|
+
has(name: string): boolean;
|
|
377
|
+
getAll(): Record<string, string>;
|
|
378
|
+
set(name: string, value: string, description?: string): void;
|
|
379
|
+
};
|
|
380
|
+
log: {
|
|
381
|
+
info(message: string, ...args: any[]): void;
|
|
382
|
+
error(message: string, ...args: any[]): void;
|
|
383
|
+
warn(message: string, ...args: any[]): void;
|
|
384
|
+
debug(message: string, ...args: any[]): void;
|
|
385
|
+
};
|
|
386
|
+
tables: {
|
|
387
|
+
list(): Promise<Array<{ id: string; name: string; description?: string; columns: Array<{ name: string; type: string; nullable: boolean }> }>>;
|
|
388
|
+
${P}
|
|
389
|
+
${M}
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
`}catch(l){return console.error("Error generating simplified context type definition:",l),`
|
|
393
|
+
declare interface Context {
|
|
394
|
+
user: {
|
|
395
|
+
id: string;
|
|
396
|
+
email: string;
|
|
397
|
+
role: 'admin' | 'user';
|
|
398
|
+
createdAt: Date;
|
|
399
|
+
updatedAt: Date;
|
|
400
|
+
};
|
|
401
|
+
http: {
|
|
402
|
+
get(url: string, options?: any): Promise<any>;
|
|
403
|
+
post(url: string, data?: any, options?: any): Promise<any>;
|
|
404
|
+
put(url: string, data?: any, options?: any): Promise<any>;
|
|
405
|
+
delete(url: string, options?: any): Promise<any>;
|
|
406
|
+
};
|
|
407
|
+
fs: {
|
|
408
|
+
readFile(path: string): Promise<string>;
|
|
409
|
+
writeFile(path: string, content: string): Promise<void>;
|
|
410
|
+
exists(path: string): Promise<boolean>;
|
|
411
|
+
listDir(path: string): Promise<string[]>;
|
|
412
|
+
mkdir(path: string): Promise<void>;
|
|
413
|
+
};
|
|
414
|
+
cmd: {
|
|
415
|
+
exec(command: string, options?: { cwd?: string; timeout?: number }): Promise<{ stdout: string; stderr: string; exitCode: number }>;
|
|
416
|
+
};
|
|
417
|
+
utils: {
|
|
418
|
+
md5(input: string): string;
|
|
419
|
+
};
|
|
420
|
+
mcp: {
|
|
421
|
+
callTool(toolName: string, args: any): Promise<any>;
|
|
422
|
+
listTools(): Promise<string[]>;
|
|
423
|
+
};
|
|
424
|
+
vars: {
|
|
425
|
+
get(name: string): string;
|
|
426
|
+
has(name: string): boolean;
|
|
427
|
+
getAll(): Record<string, string>;
|
|
428
|
+
set(name: string, value: string, description?: string): void;
|
|
429
|
+
};
|
|
430
|
+
log: {
|
|
431
|
+
info(message: string, ...args: any[]): void;
|
|
432
|
+
error(message: string, ...args: any[]): void;
|
|
433
|
+
warn(message: string, ...args: any[]): void;
|
|
434
|
+
debug(message: string, ...args: any[]): void;
|
|
435
|
+
};
|
|
436
|
+
tables: {
|
|
437
|
+
list(): Promise<Array<{ id: string; name: string; description?: string; columns: Array<{ name: string; type: string; nullable: boolean }> }>>;
|
|
438
|
+
get(tableName: string): Promise<Array<Record<string, any>>>;
|
|
439
|
+
query(tableName: string, filter?: (row: Record<string, any>) => boolean): Promise<Array<Record<string, any>>>;
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
`}}const As={class:"tools-manager"},Ms={class:"tools-toolbar"},Ds={class:"tools-table-container"},zs={class:"modal-header"},_s={class:"modal-title"},Es={class:"modal-subtitle"},Us={class:"modal-content-wrapper"},Js={class:"tab-pane-content"},Fs={class:"form-section"},Is={class:"form-grid-2"},Bs={class:"form-section"},Rs={class:"section-header"},Vs={class:"parameters-list"},Ls={class:"parameter-header"},qs={class:"parameter-index"},Hs={class:"parameter-fields"},Ks={key:0,class:"empty-parameters"},Gs={class:"tab-pane-content"},Ws={class:"save-status-indicator"},Zs=["title"],Ys={key:0,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},Qs={key:1,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},Xs={class:"monaco-wrapper"},er={class:"modal-footer"},tr={class:"test-args-content"},or={key:0,class:"test-args-parameters"},nr={class:"parameters-header"},sr={class:"parameters-count"},rr={class:"test-args-input-wrapper"},ar={class:"test-args-input-header"},lr={viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{width:"14px",height:"14px"}},ir={key:1,class:"test-result-section"},ur={class:"test-result-header"},cr={class:"test-result-title"},dr={viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{width:"18px",height:"18px","margin-right":"8px"}},pr={class:"test-result-actions"},gr={viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{width:"16px",height:"16px"}},mr={viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{width:"16px",height:"16px"}},vr={class:"test-result-content"},fr={class:"test-result-pre"},hr={class:"test-result-code-inner"},yr={class:"modal-footer"},We=`/**
|
|
443
|
+
* 工具脚本
|
|
444
|
+
* @param args 工具参数对象 (类型根据 Schema 声明自动生成)
|
|
445
|
+
* @param context 上下文对象 (提供常用工具方法等)
|
|
446
|
+
*/
|
|
447
|
+
export default async function (args: ToolArgs, context: Context) {
|
|
448
|
+
const { log } = context;
|
|
449
|
+
|
|
450
|
+
log.info('工具执行中');
|
|
451
|
+
|
|
452
|
+
return {
|
|
453
|
+
// 返回结果
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
`,wr=xt({__name:"CustomToolsManager",props:{config:{}},emits:["update"],setup(t,{emit:l}){const s=t,i=l,d=Jt(),w=N(!1),j=N(!1),T=N(null),P=N(),M=N(""),L=N("schema"),V=N(!1),B=N(!1),W=N(""),ee=N(!1),K=N("{}"),U=N(null),I=N(!1),x=Pe(()=>S.value.serverScript!==W.value),J=Pe(()=>V.value?"height: calc(100vh - 120px); border-radius: 12px; overflow: hidden;":"height: 474px; border-radius: 12px; overflow: hidden;"),ie=N([]),F=N([]),Y=v=>v?`custom_tool_script_${v}`:"custom_tool_script_new",D=v=>{const a=Y(v),f=localStorage.getItem(a);return f||null},fe=(v,a)=>{const f=Y(v);localStorage.setItem(f,a)},Ne=v=>{const a=Y(v);localStorage.removeItem(a)},he=v=>v?`custom_tool_test_args_${v}`:"custom_tool_test_args_new",xe=v=>{const a=he(v);return localStorage.getItem(a)},pe=(v,a)=>{const f=he(v);localStorage.setItem(f,a)},qe={pageSize:10,showSizePicker:!0,pageSizes:[10,20,50]},Te=v=>({style:"cursor: pointer; transition: all 0.2s ease;",onMouseenter:a=>{a.currentTarget.style.backgroundColor="rgba(99, 102, 241, 0.04)"},onMouseleave:a=>{a.currentTarget.style.backgroundColor=""}}),je=[{title:"参数名",key:"name",width:150},{title:"类型",key:"type",width:100},{title:"必需",key:"required",width:80,render:v=>v.required?ve(Vt,{type:"error"},{default:()=>"是"}):"否"},{title:"描述",key:"description",ellipsis:{tooltip:!0}}],r=[{title:"工具名称",key:"name",width:300,render(v){const a=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?a:ve("div",{style:"display: flex; align-items: center; justify-content: space-between;"},[a,ve(Lt,{trigger:"hover",style:"max-width: 600px; max-height: 500px; padding: 0; overflow: hidden;"},{trigger:()=>ve(q,{size:"tiny",tertiary:!0,circle:!0,type:"info"},{default:()=>"📄"}),default:()=>ve("div",{style:"max-height: 500px; overflow-y: auto;"},[ve(At,{size:"small",bordered:!1,columns:[{title:"参数名",key:"name",width:120},{title:"类型",key:"type",width:80},{title:"必需",key:"required",width:60,render:f=>f.required?ve(Vt,{type:"error"},{default:()=>"是"}):"否"},{title:"描述",key:"description"}],data:v.parameters,pagination:!1,singleLine:!1})])})])}},{title:"脚本",key:"script",width:150,render(v){return v.serverScript?ve(Lt,{trigger:"hover",placement:"right",style:"max-width: 600px; max-height: 500px; overflow: hidden;"},{trigger:()=>ve(st,{type:"info",size:"small",bordered:!0,style:"cursor: pointer;"},{default:()=>"Typescript"}),default:()=>ve(ko,{code:v.serverScript,language:"typescript",style:"max-height: 500px; overflow-y: auto; font-size: 12px; display: block;"})}):ve(st,{type:"default",size:"small",bordered:!0},{default:()=>"None"})}},{title:"描述",key:"description",ellipsis:{tooltip:!0}},{title:"操作",key:"actions",width:150,render(v){return ve(xo,{size:"small"},{default:()=>[ve(q,{size:"small",onClick:()=>ct(v)},{default:()=>"编辑"}),ve(q,{size:"small",type:"error",onClick:()=>dt(v.id)},{default:()=>"删除"})]})}}],H=Pe(()=>{const v=s.config.customTools.filter(f=>(f.source||"custom")==="custom");if(!M.value)return v;const a=M.value.toLowerCase();return v.filter(f=>f.name.toLowerCase().includes(a)||f.description.toLowerCase().includes(a))});async function te(){try{const v=await de.get("/configs/all-tools");v.data.success&&v.data.data.tools?ie.value=v.data.data.tools:ie.value=[]}catch(v){console.error("Failed to load MCP tools from database:",v),ie.value=[]}}async function Oe(){try{const v=await de.get("/tables/definitions");v.data.success&&(F.value=v.data.data||[])}catch(v){console.error("Failed to load tables:",v),F.value=[]}}const Se=Pe(()=>{let v=ie.value;if(T.value&&S.value.name){const a={name:S.value.name,description:S.value.description||"",inputSchema:{type:"object",properties:S.value.parameters.reduce((f,Z)=>(Z.name&&Z.name.trim()&&(f[Z.name.trim()]={type:Z.type,description:Z.description||""}),f),{}),required:S.value.parameters.filter(f=>f.required).map(f=>f.name.trim())}};v=v.filter(f=>f.name!==S.value.name).concat(a)}return Et({config:s.config,mcpTools:v,tables:F.value})}),Ue=Pe(()=>!S.value.parameters||S.value.parameters.length===0?`
|
|
457
|
+
/**
|
|
458
|
+
* 工具参数类型
|
|
459
|
+
*/
|
|
460
|
+
declare interface ToolArgs {
|
|
461
|
+
[key: string]: any;
|
|
462
|
+
}
|
|
463
|
+
`:`
|
|
464
|
+
/**
|
|
465
|
+
* 工具参数类型
|
|
466
|
+
* 根据 Schema 声明自动生成
|
|
467
|
+
*/
|
|
468
|
+
declare interface ToolArgs {
|
|
469
|
+
${S.value.parameters.filter(a=>a.name&&a.name.trim()).map(a=>{const f=a.name.trim(),re=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(f)?f:`"${f.replace(/"/g,'\\"')}"`,$e=a.required?"":"?",ge=a.description?`/** ${a.description.replace(/\*\//g,"* /")} */
|
|
470
|
+
`:"";let ye="any";switch(a.type){case"string":ye="string";break;case"number":ye="number";break;case"boolean":ye="boolean";break;case"object":ye="Record<string, any>";break;case"array":ye="any[]";break;default:ye="any"}return`${ge}${re}${$e}: ${ye};`}).join(`
|
|
471
|
+
`)}
|
|
472
|
+
}
|
|
473
|
+
`),Ae=N(0),He=Pe(()=>[{content:Se.value,filePath:"file:///context.d.ts"},{content:Ue.value,filePath:"file:///tool-args.d.ts"}]),S=N({name:"",description:"",serverScript:We,parameters:[]}),Fe=[{label:"string",value:"string"},{label:"number",value:"number"},{label:"boolean",value:"boolean"},{label:"object",value:"object"},{label:"array",value:"array"}],Ie={name:{required:!0,message:"请输入工具名称",trigger:"blur"},description:{required:!0,message:"请输入描述",trigger:"blur"}};function Tt(){return{name:"",type:"string",description:"",required:!1}}function ut(){const v={};return S.value.parameters.forEach(a=>{if(a.name&&a.name.trim())switch(a.type){case"number":v[a.name]=0;break;case"boolean":v[a.name]=!1;break;case"array":v[a.name]=[];break;case"object":v[a.name]={};break;default:v[a.name]=""}}),JSON.stringify(v,null,2)}function ct(v){T.value=v;const f=D(v.id)||v.serverScript||We;S.value={name:v.name,description:v.description,serverScript:f,parameters:v.parameters?JSON.parse(JSON.stringify(v.parameters)):[]},W.value=v.serverScript||"",w.value=!0}function dt(v){const a=s.config.customTools.filter(f=>f.id!==v);i("update",{customTools:a})}async function St(){var v,a,f;try{if(await((v=P.value)==null?void 0:v.validate()),j.value=!0,!S.value.serverScript)throw new Error("脚本不能为空");const Z={id:((a=T.value)==null?void 0:a.id)||ot(),name:S.value.name,description:S.value.description,serverScript:S.value.serverScript,parameters:S.value.parameters,source:((f=T.value)==null?void 0:f.source)||"custom"},re=[...s.config.customTools],$e=re.findIndex(ge=>ge.id===Z.id);$e!==-1?re[$e]=Z:re.push(Z),i("update",{customTools:re}),Ne(Z.id),Ne(null),w.value=!1,et()}catch(Z){d.error(Z.message)}finally{j.value=!1}}function $t(v){var f;const a=((f=T.value)==null?void 0:f.id)||null;fe(a,v)}function Qe(){var a;W.value=S.value.serverScript;const v=((a=T.value)==null?void 0:a.id)||null;fe(v,S.value.serverScript),d.success("脚本已保存")}async function Pt(){var v,a,f,Z,re,$e;if(!S.value.serverScript.trim()){d.warning("请先编写脚本内容"),ee.value=!1;return}Qe(),B.value=!0,U.value=null,I.value=!1;try{let ge={};try{const ze=K.value.trim()||"{}";if(ge=JSON.parse(ze),typeof ge!="object"||Array.isArray(ge))throw new Error("参数必须是 JSON 对象")}catch(ze){d.error(`参数格式错误: ${ze.message}`),B.value=!1;return}const ye=await de.post("/configs/test-custom-tool",{script:S.value.serverScript,args:ge,toolName:S.value.name||"test-tool"});if(ye.data.success){const ze=((v=T.value)==null?void 0:v.id)||null;pe(ze,K.value);const Be=(a=ye.data.data)==null?void 0:a.result;U.value=Be,I.value=!0,d.success("测试执行成功")}else U.value={error:ye.data.error,success:!1},I.value=!0,d.error(`测试执行失败: ${ye.data.error}`)}catch(ge){U.value={error:((Z=(f=ge.response)==null?void 0:f.data)==null?void 0:Z.error)||ge.message,success:!1},I.value=!0,d.error(`测试执行失败: ${(($e=(re=ge.response)==null?void 0:re.data)==null?void 0:$e.error)||ge.message}`)}finally{B.value=!1}}function be(v){try{return JSON.stringify(v,null,2)}catch{return String(v)}}async function Ke(){if(U.value)try{const v=be(U.value);await navigator.clipboard.writeText(v),d.success("测试结果已复制到剪贴板")}catch{try{const a=be(U.value),f=document.createElement("textarea");f.value=a,f.style.position="fixed",f.style.left="-999999px",f.style.top="-999999px",document.body.appendChild(f),f.focus(),f.select();const Z=document.execCommand("copy");document.body.removeChild(f),Z?d.success("测试结果已复制到剪贴板"):d.error("复制失败,请手动复制")}catch{d.error("复制失败,请手动复制")}}}function pt(){K.value=ut(),d.info("已重置为默认参数")}function gt(){ee.value=!1,U.value=null,I.value=!1}function mt(){V.value=!V.value}function Xe(v){const a=v.match(/export\s+default\s+async\s+function\s*(\w+)?\s*\([^)]*\)\s*\{([\s\S]*)\}/);return a&&a[1]?a[1].trim():v}async function Ge(){try{let v=ie.value;if(T.value&&S.value.name){const n={name:S.value.name,description:S.value.description||"",inputSchema:{type:"object",properties:S.value.parameters.reduce((h,m)=>(m.name&&m.name.trim()&&(h[m.name.trim()]={type:m.type,description:m.description||""}),h),{}),required:S.value.parameters.filter(h=>h.required).map(h=>h.name.trim())}};v=v.filter(h=>h.name!==S.value.name).concat(n)}const a=Et({config:s.config,mcpTools:v,tables:F.value}),f=Ue.value,Z=S.value.parameters.filter(n=>n.name&&n.name.trim()).map(n=>`- ${n.name} (${n.type}${n.required?", required":", optional"}): ${n.description||"无描述"}`).join(`
|
|
474
|
+
`),re=F.value.length>0?F.value.map(n=>`- ${n.name}${n.description?`: ${n.description}`:""}`).join(`
|
|
475
|
+
`):"暂无可用数据表",$e=S.value.serverScript.trim()||We,ge=Xe($e),ye=Xe(We),ze=$e!==We&&ge!==ye,Be=S.value.name||"未命名工具",c=S.value.description||"无描述",e=ze?`请帮我调整/优化以下函数的实现。工具名称:${Be},描述:${c}。
|
|
476
|
+
|
|
477
|
+
## 需求描述
|
|
478
|
+
|
|
479
|
+
[请在此处补充你的具体需求描述,说明需要如何调整或优化当前实现]
|
|
480
|
+
|
|
481
|
+
## 类型定义
|
|
482
|
+
|
|
483
|
+
### Context 类型定义
|
|
484
|
+
|
|
485
|
+
\`\`\`typescript
|
|
486
|
+
${a}
|
|
487
|
+
\`\`\`
|
|
488
|
+
|
|
489
|
+
### ToolArgs 类型定义
|
|
490
|
+
|
|
491
|
+
\`\`\`typescript
|
|
492
|
+
${f}
|
|
493
|
+
\`\`\`
|
|
494
|
+
|
|
495
|
+
## 工具参数定义
|
|
496
|
+
|
|
497
|
+
${Z||"暂无参数定义"}
|
|
498
|
+
|
|
499
|
+
# 可用表列表:
|
|
500
|
+
|
|
501
|
+
${re}
|
|
502
|
+
|
|
503
|
+
## 当前实现
|
|
504
|
+
|
|
505
|
+
\`\`\`typescript
|
|
506
|
+
export default async function(args: ToolArgs, context: Context) {
|
|
507
|
+
${ge}
|
|
508
|
+
}
|
|
509
|
+
\`\`\`
|
|
510
|
+
|
|
511
|
+
## 输出格式
|
|
512
|
+
|
|
513
|
+
只输出以下函数定义代码(类型部分不必输出),格式如下:
|
|
514
|
+
|
|
515
|
+
\`\`\`typescript
|
|
516
|
+
export default async function(args: ToolArgs, context: Context) {
|
|
517
|
+
// 函数体
|
|
518
|
+
}
|
|
519
|
+
\`\`\`
|
|
520
|
+
|
|
521
|
+
不要输出任何注释、解释文字或其他内容。
|
|
522
|
+
|
|
523
|
+
## 约束
|
|
524
|
+
|
|
525
|
+
- 只能使用 args 和 context 参数中的 API`:`请帮我实现以下函数。工具名称:${Be},描述:${c}。
|
|
526
|
+
|
|
527
|
+
## 需求描述
|
|
528
|
+
|
|
529
|
+
[请在此处补充你的具体需求描述]
|
|
530
|
+
|
|
531
|
+
## 类型定义
|
|
532
|
+
|
|
533
|
+
### Context 类型定义
|
|
534
|
+
|
|
535
|
+
\`\`\`typescript
|
|
536
|
+
${a}
|
|
537
|
+
\`\`\`
|
|
538
|
+
|
|
539
|
+
### ToolArgs 类型定义
|
|
540
|
+
|
|
541
|
+
\`\`\`typescript
|
|
542
|
+
${f}
|
|
543
|
+
\`\`\`
|
|
544
|
+
|
|
545
|
+
## 工具参数定义
|
|
546
|
+
|
|
547
|
+
${Z||"暂无参数定义"}
|
|
548
|
+
|
|
549
|
+
# 可用表列表:
|
|
550
|
+
|
|
551
|
+
${re}
|
|
552
|
+
|
|
553
|
+
## 函数签名
|
|
554
|
+
|
|
555
|
+
\`\`\`typescript
|
|
556
|
+
export default async function(args: ToolArgs, context: Context) {
|
|
557
|
+
// 在此处实现
|
|
558
|
+
}
|
|
559
|
+
\`\`\`
|
|
560
|
+
|
|
561
|
+
## 输出格式
|
|
562
|
+
|
|
563
|
+
只输出以下函数定义代码(类型部分不必输出),格式如下:
|
|
564
|
+
|
|
565
|
+
\`\`\`typescript
|
|
566
|
+
export default async function(args: ToolArgs, context: Context) {
|
|
567
|
+
// 函数体
|
|
568
|
+
}
|
|
569
|
+
\`\`\`
|
|
570
|
+
|
|
571
|
+
不要输出任何注释、解释文字或其他内容。
|
|
572
|
+
|
|
573
|
+
## 约束
|
|
574
|
+
|
|
575
|
+
- 只能使用 args 和 context 参数中的 API`;await navigator.clipboard.writeText(e),d.success("提示词已复制到剪贴板!")}catch(v){console.error("Failed to copy prompt:",v),d.error("复制失败,请手动复制")}}function et(){T.value=null,L.value="schema",V.value=!1,ee.value=!1,K.value="{}",U.value=null,I.value=!1;const v=D(null);S.value={name:"",description:"",serverScript:v||We,parameters:[]},W.value=""}return Ut(()=>{te(),Oe()}),Ce(()=>s.config.components,()=>{te()},{deep:!0}),Ce(()=>L.value,v=>{v==="implementation"&&Le(()=>{Ae.value++})}),Ce(()=>S.value.parameters,()=>{Le(()=>{Ae.value++})},{deep:!0,immediate:!1}),Ce(()=>[S.value.name,S.value.description],()=>{Le(()=>{Ae.value++})},{immediate:!1}),Ce(()=>ee.value,v=>{var a;if(v){const f=((a=T.value)==null?void 0:a.id)||null,Z=xe(f);Z?K.value=Z:K.value=ut()}}),Ce(()=>s.config.customTools,()=>{te()},{deep:!0}),Ce(()=>w.value,v=>{if(v){if(!T.value){const a=D(null);a&&(S.value.serverScript=a)}}else et()}),(v,a)=>(_(),R("div",As,[o("div",Ms,[g(p(q),{type:"primary",size:"large",class:"add-tool-btn",onClick:a[0]||(a[0]=f=>w.value=!0)},{icon:u(()=>[...a[13]||(a[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:u(()=>[a[14]||(a[14]=E(" 添加工具 ",-1))]),_:1}),g(p(we),{value:M.value,"onUpdate:value":a[1]||(a[1]=f=>M.value=f),placeholder:"搜索工具名称或描述...",size:"large",clearable:"",class:"search-input"},{prefix:u(()=>[...a[15]||(a[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",Ds,[g(p(At),{columns:r,data:H.value,pagination:qe,"row-props":Te,class:"modern-table"},null,8,["data"])]),g(p(bt),{show:w.value,"onUpdate:show":a[9]||(a[9]=f=>w.value=f),preset:"card",bordered:!1,class:"tool-edit-modal",style:{width:"90vw",maxWidth:"1400px",height:"90vh",maxHeight:"90vh"}},{header:u(()=>[o("div",zs,[a[16]||(a[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",_s,X(T.value?"编辑自定义工具":"创建自定义工具"),1),o("p",Es,X(T.value?"修改工具的 Schema 和实现代码":"定义工具的 Schema 并编写实现逻辑"),1)])])]),footer:u(()=>[o("div",er,[g(p(q),{size:"large",onClick:a[8]||(a[8]=f=>w.value=!1)},{default:u(()=>[...a[36]||(a[36]=[E("取消",-1)])]),_:1}),g(p(q),{type:"primary",size:"large",loading:j.value,onClick:St},{default:u(()=>[E(X(T.value?"保存修改":"创建工具"),1)]),_:1},8,["loading"])])]),default:u(()=>[o("div",Us,[g(p(to),{ref_key:"formRef",ref:P,model:S.value,rules:Ie,class:"tool-form"},{default:u(()=>[g(p(eo),{value:L.value,"onUpdate:value":a[7]||(a[7]=f=>L.value=f),type:"line",animated:"",size:"large",class:"tool-config-tabs"},{default:u(()=>[g(p(rt),{name:"schema",tab:"Schema 声明"},{default:u(()=>[o("div",Js,[g(p(Ve),{type:"info",bordered:!1,class:"schema-tip"},{icon:u(()=>[...a[17]||(a[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:u(()=>[a[18]||(a[18]=E(' 在 Schema 声明中定义的参数会自动生成类型定义,在"工具实现"标签页的脚本编辑器中可以使用类型提示 ',-1))]),_:1}),o("div",Fs,[a[21]||(a[21]=o("h4",{class:"section-title"},"基础信息",-1)),o("div",Is,[g(p(ce),{path:"name"},{label:u(()=>[...a[19]||(a[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:u(()=>[g(p(we),{value:S.value.name,"onUpdate:value":a[2]||(a[2]=f=>S.value.name=f),placeholder:"例如: my-custom-tool",size:"large"},null,8,["value"])]),_:1}),g(p(ce),{path:"description"},{label:u(()=>[...a[20]||(a[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:u(()=>[g(p(we),{value:S.value.description,"onUpdate:value":a[3]||(a[3]=f=>S.value.description=f),placeholder:"简要描述工具的功能",size:"large"},null,8,["value"])]),_:1})])]),o("div",Bs,[o("div",Rs,[a[24]||(a[24]=o("h4",{class:"section-title"},"参数定义",-1)),g(p(q),{dashed:"",onClick:a[4]||(a[4]=f=>S.value.parameters.push(Tt())),size:"medium"},{icon:u(()=>[...a[22]||(a[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:u(()=>[a[23]||(a[23]=E(" 添加参数 ",-1))]),_:1})]),o("div",Vs,[(_(!0),R(ht,null,yt(S.value.parameters,(f,Z)=>(_(),R("div",{key:Z,class:"parameter-card"},[o("div",Ls,[o("span",qs,"#"+X(Z+1),1),g(p(q),{type:"error",text:"",size:"small",onClick:re=>S.value.parameters.splice(Z,1)},{icon:u(()=>[...a[25]||(a[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:u(()=>[a[26]||(a[26]=E(" 删除 ",-1))]),_:1},8,["onClick"])]),o("div",Hs,[g(p(ce),{label:"必填",class:"required-field"},{default:u(()=>[g(p(no),{checked:f.required,"onUpdate:checked":re=>f.required=re},null,8,["checked","onUpdate:checked"])]),_:2},1024),g(p(ce),{label:"参数名",path:`parameters[${Z}].name`,rule:{required:!0,message:"必填",trigger:"blur"}},{default:u(()=>[g(p(we),{value:f.name,"onUpdate:value":re=>f.name=re,placeholder:"参数名"},null,8,["value","onUpdate:value"])]),_:2},1032,["path"]),g(p(ce),{label:"类型"},{default:u(()=>[g(p(oo),{value:f.type,"onUpdate:value":re=>f.type=re,options:Fe},null,8,["value","onUpdate:value"])]),_:2},1024),g(p(ce),{label:"描述"},{default:u(()=>[g(p(we),{value:f.description,"onUpdate:value":re=>f.description=re,placeholder:"参数描述"},null,8,["value","onUpdate:value"])]),_:2},1024)])]))),128)),S.value.parameters.length===0?(_(),R("div",Ks,[...a[27]||(a[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)])])):ue("",!0)])])])]),_:1}),g(p(rt),{name:"implementation",tab:"工具实现"},{default:u(()=>[o("div",Gs,[o("div",{class:Ee(["editor-container",{fullscreen:V.value}])},[o("div",Ws,[o("div",{class:Ee(["status-dot",{unsaved:x.value,saved:!x.value}]),title:x.value?"未保存":"已保存"},null,10,Zs)]),g(p(q),{type:"default",size:"small",class:"fullscreen-btn",onClick:mt},{icon:u(()=>[V.value?(_(),R("svg",Qs,[...a[29]||(a[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)])])):(_(),R("svg",Ys,[...a[28]||(a[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:u(()=>[E(" "+X(V.value?"退出全屏":"全屏"),1)]),_:1}),o("div",Xs,[g(at,{modelValue:S.value.serverScript,"onUpdate:modelValue":a[5]||(a[5]=f=>S.value.serverScript=f),language:"typescript",options:{minimap:{enabled:!0},fontSize:14,lineHeight:22,padding:{top:16,bottom:16},scrollBeyondLastLine:!1,automaticLayout:!0},"extra-libs":He.value,onSave:Qe,onChange:$t,style:_t(J.value)},null,8,["modelValue","extra-libs","style"])])],2),o("div",{class:Ee(["editor-actions",{"fullscreen-actions":V.value}])},[g(p(q),{type:"default",size:"small",class:"copy-prompt-btn",onClick:Ge},{icon:u(()=>[...a[30]||(a[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:u(()=>[a[31]||(a[31]=E(" 复制提示词到大模型生成 ",-1))]),_:1}),g(p(q),{type:"primary",size:"small",class:"save-btn",disabled:!x.value,onClick:Qe},{icon:u(()=>[...a[32]||(a[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:u(()=>[a[33]||(a[33]=E(" 保存 (Ctrl+S) ",-1))]),_:1},8,["disabled"]),g(p(q),{type:"info",size:"small",class:"test-btn",loading:B.value,onClick:a[6]||(a[6]=f=>ee.value=!0)},{icon:u(()=>[...a[34]||(a[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:u(()=>[a[35]||(a[35]=E(" 测试执行 ",-1))]),_:1},8,["loading"])],2)])]),_:1})]),_:1},8,["value"])]),_:1},8,["model"])])]),_:1},8,["show"]),g(p(bt),{show:ee.value,"onUpdate:show":a[12]||(a[12]=f=>ee.value=f),preset:"card",bordered:!1,class:"test-args-modal",style:_t({width:I.value?"800px":"600px"}),title:"测试执行参数"},{header:u(()=>[...a[37]||(a[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:u(()=>[o("div",yr,[g(p(q),{size:"large",onClick:gt},{default:u(()=>[...a[48]||(a[48]=[E("取消",-1)])]),_:1}),g(p(q),{type:"primary",size:"large",loading:B.value,onClick:Pt},{default:u(()=>[...a[49]||(a[49]=[E(" 执行测试 ",-1)])]),_:1},8,["loading"])])]),default:u(()=>[o("div",tr,[S.value.parameters&&S.value.parameters.length>0?(_(),R("div",or,[o("div",nr,[a[38]||(a[38]=o("span",{class:"parameters-title"},"参数定义",-1)),o("span",sr,X(S.value.parameters.length)+" 个参数",1)]),g(p(At),{columns:je,data:S.value.parameters.filter(f=>f.name&&f.name.trim()),pagination:!1,size:"small",bordered:"",class:"test-args-table"},null,8,["data"])])):ue("",!0),o("div",rr,[o("div",ar,[a[41]||(a[41]=o("span",{class:"test-args-input-title"},"测试参数 (JSON)",-1)),g(p(q),{size:"small",type:"default",onClick:pt},{icon:u(()=>[(_(),R("svg",lr,[...a[39]||(a[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:u(()=>[a[40]||(a[40]=E(" 重置 ",-1))]),_:1})]),g(p(we),{value:K.value,"onUpdate:value":a[10]||(a[10]=f=>K.value=f),type:"textarea",placeholder:'{"param1": "value1", "param2": 123}',rows:8,autosize:{minRows:8,maxRows:12},class:"test-args-input"},null,8,["value"])]),I.value&&U.value?(_(),R("div",ir,[o("div",ur,[o("div",cr,[(_(),R("svg",dr,[...a[42]||(a[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)])])),a[43]||(a[43]=o("span",null,"测试结果",-1))]),o("div",pr,[g(p(q),{size:"small",text:"",onClick:Ke},{icon:u(()=>[(_(),R("svg",gr,[...a[44]||(a[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:u(()=>[a[45]||(a[45]=E(" 复制 ",-1))]),_:1}),g(p(q),{size:"small",text:"",onClick:a[11]||(a[11]=f=>I.value=!1)},{icon:u(()=>[(_(),R("svg",mr,[...a[46]||(a[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",vr,[o("pre",fr,[o("code",hr,X(be(U.value)),1),a[47]||(a[47]=E(`
|
|
576
|
+
`,-1))])])])):ue("",!0)])]),_:1},8,["show","style"])]))}}),Dr=Ft(wr,[["__scopeId","data-v-6b73ec28"]]),br={class:"init-script-editor"},kr={class:"save-status-indicator"},xr=["title"],Cr={key:0,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},Tr={key:1,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},Sr={class:"monaco-wrapper"},$r={class:"editor-actions"},Ze=`/**
|
|
577
|
+
* MCP 初始化脚本
|
|
578
|
+
* 在 MCP 客户端连接时执行,用于环境检查、数据预加载等操作
|
|
579
|
+
*/
|
|
580
|
+
export default async function(context: Context) {
|
|
581
|
+
const { log } = context;
|
|
582
|
+
|
|
583
|
+
log.info('🚀 MCP 环境初始化完成');
|
|
584
|
+
|
|
585
|
+
// 示例:检查变量配置
|
|
586
|
+
// const apiKey = context.vars.get('API_KEY');
|
|
587
|
+
// if (!apiKey) {
|
|
588
|
+
// log.warn('⚠️ API_KEY 未配置');
|
|
589
|
+
// }
|
|
590
|
+
}`,zt="init-script-local-draft",Pr=xt({__name:"InitScriptEditor",props:{config:{}},emits:["update"],setup(t,{emit:l}){const s=Jt(),i=t,d=l,w=N([]),j=N([]);async function T(){try{const r=await de.get("/configs/all-tools");r.data.success&&r.data.data.tools?w.value=r.data.data.tools:w.value=[]}catch(r){console.error("Failed to load MCP tools from database:",r),w.value=[]}}async function P(){try{const r=await de.get("/tables/definitions");r.data.success&&(j.value=r.data.data||[])}catch(r){console.error("Failed to load tables:",r),j.value=[]}}const M=Pe(()=>Et({config:i.config,mcpTools:w.value,tables:j.value})),L=Pe(()=>[{content:M.value,filePath:"file:///init-script-context.d.ts"}]);Ut(()=>{T(),P()}),Ce(()=>i.config.components,()=>{T()},{deep:!0}),Ce(()=>i.config.customTools,()=>{T()},{deep:!0});function V(){try{return localStorage.getItem(zt)||null}catch(r){return console.error("Failed to load local script:",r),null}}function B(r){try{localStorage.setItem(zt,r)}catch(H){console.error("Failed to save to local storage:",H)}}function W(){try{localStorage.removeItem(zt)}catch(r){console.error("Failed to clear local script:",r)}}const ee=V(),K=i.config.initScript||"",I=N(ee||K||Ze),x=N(K),J=N(ee||""),ie=Pe(()=>I.value!==J.value),F=Pe(()=>J.value!==x.value),Y=N(!1),D=N(!1),fe=Pe(()=>D.value?"height: 100%; border-radius: 12px; overflow: hidden;":"height: calc(100vh - 300px); min-height: 600px; max-height: 800px; border-radius: 12px; overflow: hidden;");Ce(()=>i.config.initScript,(r,H)=>{const te=r||"";if(te===(H||""))return;const Se=V();if(Se&&te===Se){W(),J.value="",x.value=te,I.value=te;return}if(Se&&te!==Se){W(),J.value="",x.value=te;const Ae=te||Ze;I.value=Ae;return}if(x.value=te,!te&&x.value)return;const Ue=te||Ze;I.value=Ue,x.value=te},{immediate:!0});function Ne(r){}function he(){const r=I.value.trim()||"";B(r),J.value=r,s.success("已保存到本地 (Ctrl+S)")}async function xe(){const r=J.value.trim()||void 0;d("update",{initScript:r}),x.value=r||"",W(),J.value=""}async function pe(){var r,H;if(!I.value.trim()){s.warning("请先编写脚本内容");return}he(),Y.value=!0;try{const te=await de.post("/configs/test-init-script",{script:I.value});te.data.success?s.success("测试执行成功,请查看服务端控制台输出"):s.error(`测试执行失败: ${te.data.error}`)}catch(te){s.error(`测试执行失败: ${((H=(r=te.response)==null?void 0:r.data)==null?void 0:H.error)||te.message}`)}finally{Y.value=!1}}function qe(){D.value=!D.value}function Te(r){const H=r.match(/export\s+default\s+async\s+function\s*\([^)]*\)\s*\{([\s\S]*)\}/);return H&&H[1]?H[1].trim():r}async function je(){try{const r=Os({config:i.config,mcpTools:w.value,tables:j.value}),H=w.value.map(S=>`- ${S.name}: ${S.description||"无描述"}`).join(`
|
|
591
|
+
`),te=j.value.map(S=>{const Fe=S.columns.map(Ie=>` - ${Ie.name} (${Ie.type}${Ie.nullable?", nullable":""})`).join(`
|
|
592
|
+
`);return`- ${S.name}: ${S.description||"无描述"}
|
|
593
|
+
${Fe}`}).join(`
|
|
594
|
+
|
|
595
|
+
`),Oe=I.value.trim()||Ze,Se=Te(Oe),Ue=Te(Ze),He=Oe!==Ze&&Se!==Ue?`请帮我调整/优化以下函数的实现。
|
|
596
|
+
|
|
597
|
+
## 需求描述
|
|
598
|
+
|
|
599
|
+
[请在此处补充你的具体需求描述,说明需要如何调整或优化当前实现]
|
|
600
|
+
|
|
601
|
+
## 类型定义
|
|
602
|
+
|
|
603
|
+
\`\`\`typescript
|
|
604
|
+
${r}
|
|
605
|
+
\`\`\`
|
|
606
|
+
|
|
607
|
+
## 可用工具
|
|
608
|
+
|
|
609
|
+
${H||"暂无可用工具"}
|
|
610
|
+
|
|
611
|
+
## 可用数据表
|
|
612
|
+
|
|
613
|
+
${te||"暂无可用数据表"}
|
|
614
|
+
|
|
615
|
+
## 当前实现
|
|
616
|
+
|
|
617
|
+
\`\`\`typescript
|
|
618
|
+
export default async function(context: Context) {
|
|
619
|
+
${Se}
|
|
620
|
+
}
|
|
621
|
+
\`\`\`
|
|
622
|
+
|
|
623
|
+
## 输出格式
|
|
624
|
+
|
|
625
|
+
只输出以下函数定义代码(类型部分不必输出),格式如下:
|
|
626
|
+
|
|
627
|
+
\`\`\`typescript
|
|
628
|
+
export default async function(context: Context) {
|
|
629
|
+
// 函数体
|
|
630
|
+
}
|
|
631
|
+
\`\`\`
|
|
632
|
+
|
|
633
|
+
不要输出任何注释、解释文字或其他内容。
|
|
634
|
+
|
|
635
|
+
## 约束
|
|
636
|
+
|
|
637
|
+
- 只能使用 context 参数中的 API`:`请帮我实现以下函数。
|
|
638
|
+
|
|
639
|
+
## 需求描述
|
|
640
|
+
|
|
641
|
+
[请在此处补充你的具体需求描述]
|
|
642
|
+
|
|
643
|
+
## 类型定义
|
|
644
|
+
|
|
645
|
+
\`\`\`typescript
|
|
646
|
+
${r}
|
|
647
|
+
\`\`\`
|
|
648
|
+
|
|
649
|
+
## 可用工具
|
|
650
|
+
|
|
651
|
+
${H||"暂无可用工具"}
|
|
652
|
+
|
|
653
|
+
## 可用数据表
|
|
654
|
+
|
|
655
|
+
${te||"暂无可用数据表"}
|
|
656
|
+
|
|
657
|
+
## 函数签名
|
|
658
|
+
|
|
659
|
+
\`\`\`typescript
|
|
660
|
+
export default async function(context: Context) {
|
|
661
|
+
// 在此处实现
|
|
662
|
+
}
|
|
663
|
+
\`\`\`
|
|
664
|
+
|
|
665
|
+
## 输出格式
|
|
666
|
+
|
|
667
|
+
只输出以下函数定义代码(类型部分不必输出),格式如下:
|
|
668
|
+
|
|
669
|
+
\`\`\`typescript
|
|
670
|
+
export default async function(context: Context) {
|
|
671
|
+
// 函数体
|
|
672
|
+
}
|
|
673
|
+
\`\`\`
|
|
674
|
+
|
|
675
|
+
不要输出任何注释、解释文字或其他内容。
|
|
676
|
+
|
|
677
|
+
## 约束
|
|
678
|
+
|
|
679
|
+
- 只能使用 context 参数中的 API`;await navigator.clipboard.writeText(He),s.success("提示词已复制到剪贴板!")}catch(r){console.error("Failed to copy prompt:",r),s.error("复制失败,请手动复制")}}return(r,H)=>(_(),R("div",br,[H[9]||(H[9]=Xt('<div class="editor-toolbar" data-v-515e2056><div class="toolbar-info" data-v-515e2056><svg class="info-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" data-v-515e2056><polyline points="16 18 22 12 16 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" data-v-515e2056></polyline><polyline points="8 6 2 12 8 18" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" data-v-515e2056></polyline></svg><span data-v-515e2056>初始化脚本在 MCP 连接时执行,用于初始化环境、加载数据等操作</span></div></div>',1)),o("div",{class:Ee(["editor-container",{fullscreen:D.value}])},[o("div",kr,[o("div",{class:Ee(["status-dot",{unsaved:ie.value,saved:!ie.value,"local-only":F.value&&!ie.value}]),title:ie.value?"未保存到本地":F.value?"已保存到本地,未上传":"已保存"},null,10,xr)]),g(p(q),{type:"default",size:"small",class:"fullscreen-btn",onClick:qe},{icon:u(()=>[D.value?(_(),R("svg",Tr,[...H[2]||(H[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)])])):(_(),R("svg",Cr,[...H[1]||(H[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:u(()=>[E(" "+X(D.value?"退出全屏":"全屏"),1)]),_:1}),o("div",Sr,[g(at,{modelValue:I.value,"onUpdate:modelValue":H[0]||(H[0]=te=>I.value=te),language:"typescript",options:{minimap:{enabled:!0},fontSize:14,lineHeight:22,padding:{top:16,bottom:16},scrollBeyondLastLine:!1,automaticLayout:!0},"extra-libs":L.value,onSave:he,onChange:Ne,style:_t(fe.value)},null,8,["modelValue","extra-libs","style"])]),o("div",$r,[g(p(q),{type:"default",size:"small",class:"copy-prompt-btn",onClick:je},{icon:u(()=>[...H[3]||(H[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:u(()=>[H[4]||(H[4]=E(" 复制提示词到大模型生成 ",-1))]),_:1}),g(p(q),{type:"primary",size:"small",class:"upload-btn",disabled:!F.value,onClick:xe},{icon:u(()=>[...H[5]||(H[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:u(()=>[H[6]||(H[6]=E(" 上传脚本 ",-1))]),_:1},8,["disabled"]),g(p(q),{type:"info",size:"small",class:"test-btn",loading:Y.value,onClick:pe},{icon:u(()=>[...H[7]||(H[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:u(()=>[H[8]||(H[8]=E(" 测试执行 ",-1))]),_:1},8,["loading"])])],2)]))}}),zr=Ft(Pr,[["__scopeId","data-v-515e2056"]]);export{Dr as C,zr as I,Mr as M,at as _,ot as g,Ar as p,Or as u};
|