flex-mcp 1.0.3 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/api/configs.d.ts.map +1 -1
  2. package/dist/api/configs.js +92 -44
  3. package/dist/api/configs.js.map +1 -1
  4. package/dist/api/prompts.d.ts.map +1 -1
  5. package/dist/api/prompts.js +1 -58
  6. package/dist/api/prompts.js.map +1 -1
  7. package/dist/mcp/aggregator.d.ts +5 -1
  8. package/dist/mcp/aggregator.d.ts.map +1 -1
  9. package/dist/mcp/aggregator.js +76 -50
  10. package/dist/mcp/aggregator.js.map +1 -1
  11. package/dist/mcp/post-sse-transport.d.ts +4 -0
  12. package/dist/mcp/post-sse-transport.d.ts.map +1 -1
  13. package/dist/mcp/post-sse-transport.js +118 -5
  14. package/dist/mcp/post-sse-transport.js.map +1 -1
  15. package/dist/mcp/tool-sync.d.ts.map +1 -1
  16. package/dist/mcp/tool-sync.js +12 -14
  17. package/dist/mcp/tool-sync.js.map +1 -1
  18. package/dist/script/context.d.ts +1 -1
  19. package/dist/script/context.d.ts.map +1 -1
  20. package/dist/script/context.js +5 -1
  21. package/dist/script/context.js.map +1 -1
  22. package/dist/script/executor.d.ts +9 -0
  23. package/dist/script/executor.d.ts.map +1 -1
  24. package/dist/script/executor.js +19 -1
  25. package/dist/script/executor.js.map +1 -1
  26. package/dist/web/assets/{Blank-s8a1VcBP.js → Blank-2vpGi200.js} +1 -1
  27. package/dist/web/assets/Configs-4PrDyfwx.js +1 -0
  28. package/dist/web/assets/Dashboard-D8vYINT3.js +30 -0
  29. package/dist/web/assets/InitScriptEditor-RtEtxdk9.js +679 -0
  30. package/dist/web/assets/{Layout-C1hga5lx.js → Layout-C5VF6KaE.js} +1 -1
  31. package/dist/web/assets/{Layout-BkmH4NiL.js → Layout-CYzaFG4l.js} +1 -1
  32. package/dist/web/assets/{Login-DflsSakB.js → Login-DEm7Yc0V.js} +1 -1
  33. package/dist/web/assets/{Login-Dbjg2uN-.js → Login-uQx8mYT4.js} +1 -1
  34. package/dist/web/assets/Users-zZdxWL7h.js +1 -0
  35. package/dist/web/assets/{index-Coivokd4.js → index-NmCbGUEa.js} +3 -3
  36. package/dist/web/assets/style-hUGligFl.css +1 -0
  37. package/dist/web/index.html +2 -2
  38. package/package.json +1 -1
  39. package/dist/api/resources.d.ts +0 -6
  40. package/dist/api/resources.d.ts.map +0 -1
  41. package/dist/api/resources.js +0 -159
  42. package/dist/api/resources.js.map +0 -1
  43. package/dist/web/assets/Configs-Du0LnEIl.js +0 -1
  44. package/dist/web/assets/Dashboard-DBtv2jAX.js +0 -27
  45. package/dist/web/assets/InitScriptEditor-CyQQvKeL.js +0 -675
  46. package/dist/web/assets/Users-DKoYWDA0.js +0 -1
  47. package/dist/web/assets/style-DkqnAI3H.css +0 -1
@@ -0,0 +1,679 @@
1
+ import{a1 as co,r as N,J as de,d as Ct,I as Ut,U as po,A as xe,c as V,o as _,u as Jt,p as Pe,m as ue,f as g,b as o,w as c,g as p,B as q,a2 as go,e as Xt,D as bt,h as J,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 Co}from"./index-NmCbGUEa.js";import{_ as Ft}from"./_plugin-vue_export-helper-DlAUqK2U.js";const jr=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 R=await de.get(`/configs/user/${P}`);return t.value=R.data.data,t.value}catch(R){throw new Error(((L=(M=R.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 R=await de.put("/configs/me",P);return t.value=R.data.data,t.value}catch(R){throw new Error(((L=(M=R.response)==null?void 0:M.data)==null?void 0:L.error)||"Failed to update config")}finally{l.value=!1}}async function h(P,M){var L,R;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(((R=(L=B.response)==null?void 0:L.data)==null?void 0:R.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:h,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 xo(t,l){let s=t;const i=/\{\{#if\s+(\w+)\}\}([\s\S]*?)(?:\{\{else\}\}([\s\S]*?))?\{\{\/if\}\}/g;s=s.replace(i,(h,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,(h,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 Nr(t,l){let s=xo(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,h,j,T=[],P=!0,M=!1;try{if(h=(s=s.call(t)).next,l!==0)for(;!(P=(i=h.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 h=Object.getOwnPropertySymbols(t);for(i=0;i<h.length;i++)s=h[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,h){return h(d)},i)}}function nt(t){return function l(){for(var s=this,i=arguments.length,d=new Array(i),h=0;h<i;h++)d[h]=arguments[h];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),h=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,h,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),h=0;h<i;h++)d[h]=arguments[h];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(h,j){return j(h)},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(h){return l?d(sn):i(h)}),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],xt=ao[1];function ln(t){var l=on.config(t),s=l.monaco,i=No(l,rn);xt(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(xt({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,h=i.reject;return{config:d,reject:h}}),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,h=s.reject;return{config:i,resolve:d,reject:h}}),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||xt({monaco:t})}function mn(){return it(function(t){var l=t.monaco;return l})}var Dt=new Promise(function(t,l){return xt({resolve:t,reject:l})}),vn={config:ln,init:un,__getMonacoInstance:mn};const at=Ct({__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 h=null,j=null,T=null,P=!1,M=null;const L=N(new Map);function R(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 I=K.filePath||`file:///lib-${Date.now()}.d.ts`,F=ee.addExtraLib(K.content,I);L.value.set(I,F)})}return Ut(async()=>{var Z,ee,K;j=await vn.init(),s.extraLibs&&R(s.extraLibs);const B=s.language||"typescript";T&&T.dispose(),T=j.languages.registerCompletionItemProvider(B,{provideCompletionItems:()=>({suggestions:[]}),triggerCharacters:['"',"'"]}),h=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,...(Z=s.options)==null?void 0:Z.quickSuggestions},suggestOnTriggerCharacters:((ee=s.options)==null?void 0:ee.suggestOnTriggerCharacters)??!0,wordWrap:((K=s.options)==null?void 0:K.wordWrap)??"off"}),h.onDidChangeModelContent(I=>{var E;if(P)return;const F=h.getValue();i("update:modelValue",F),i("change",F);const C=(E=I.changes)==null?void 0:E[I.changes.length-1];C&&(C.text==='"'||C.text==="'")&&setTimeout(()=>{h&&h.trigger("","editor.action.triggerSuggest",{})},100)}),h.addCommand(j.KeyMod.CtrlCmd|j.KeyCode.KeyS,()=>{i("save")}),M=I=>{if(!(!h||!h.hasTextFocus())){if((I.metaKey||I.ctrlKey)&&I.key==="z"&&!I.shiftKey){I.preventDefault(),I.stopPropagation();const F=h.getModel();return F&&F.canUndo()&&F.undo(),!1}if((I.metaKey||I.ctrlKey)&&I.key==="z"&&I.shiftKey){I.preventDefault(),I.stopPropagation();const F=h.getModel();return F&&F.canRedo()&&F.redo(),!1}if((I.metaKey||I.ctrlKey)&&I.key==="y"){I.preventDefault(),I.stopPropagation();const F=h.getModel();return F&&F.canRedo()&&F.redo(),!1}}},document.addEventListener("keydown",M,!0)}),po(()=>{T==null||T.dispose(),h==null||h.dispose(),M&&(document.removeEventListener("keydown",M,!0),M=null)}),xe(()=>s.modelValue,B=>{if(!h)return;if(h.getValue()!==B){P=!0;try{const ee=h.getModel();if(ee){const K=ee.getFullModelRange();h.executeEdits("external-update",[{range:K,text:B}]),h.pushUndoStop();const I=ee.getLineCount(),F=ee.getLineMaxColumn(I);h.setPosition({lineNumber:I,column:F})}}finally{setTimeout(()=>{P=!1},0)}}}),xe(()=>s.extraLibs,(B,Z)=>{if(!B||!j||!(!Z||B.length!==Z.length||B.some((I,F)=>{const C=Z[F];return!C||I.content!==C.content||I.filePath!==C.filePath})))return;R(B);const K=h==null?void 0:h.getModel();K&&(j.editor.setModelMarkers(K,"typescript",[]),setTimeout(()=>{h&&K&&K.getValue()===K.getValue()&&K.forceTokenization(K.getLineCount())},100))},{deep:!0,immediate:!1}),(B,Z)=>(_(),V("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"},Cn={class:"component-icon"},xn={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"},Cs={class:"schema-tool-info"},xs={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=Ct({__name:"MCPComponentsManager",props:{config:{}},emits:["update"],setup(t,{emit:l}){const s=t,i=l,d=Jt(),h=N(!1),j=N("config"),T=N("form"),P=N(!1),M=N(!1),L=N(!1),R=N(!1),B=N(""),Z=N(null),ee=N(),K=N(""),I=N(""),F=N({}),C=N(!1),E=N({current:0,total:0,currentComponent:""});function ie(u){j.value=u}const U=N([]),Y=N(new Set),D=N({}),fe=N(0),Ne=Pe(()=>{const u=r.value.toolPatches,e=D.value,n=U.value;fe.value;const y={};return n.forEach(v=>{var b;const f=Se(v),$=u[f];$&&$.description!==void 0&&$.description!==null&&$.description!==""?y[v.name]=$.description:y[v.name]=((b=e[f])==null?void 0:b.description)||"暂无描述"}),y}),he=N(null),ke=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(u){const e={};return u.forEach(n=>{n.key&&(e[n.key]=n.value)}),e}function $e(u){return u?Object.entries(u).map(([e,n])=>({key:e,value:n})):[]}function Ue(u,e){const n=[...s.config.components],y=n.findIndex(v=>v.id===u.id);y!==-1&&(n[y]={...u,disabled:!e},i("update",{components:n}))}function Ae(u){var A,se,ne;const e=(A=u.config)!=null&&A.headers?$e(u.config.headers):[],n=((se=u.config)==null?void 0:se.disabledTools)||[],y=(ne=u.config)!=null&&ne.toolPatches?JSON.parse(JSON.stringify(u.config.toolPatches)):{};console.log("加载时的 toolPatches:",JSON.stringify(y,null,2));const{headers:v,disabledTools:f,toolPatches:$,tools:x,...b}=u.config||{},oe=["id","name","type","namespace","env","package","version","url","command","args","config","disabled"],O={};Object.keys(u).forEach(z=>{oe.includes(z)||(O[z]=u[z])}),r.value={name:u.name||"",type:u.type||"npm",package:u.package||"",version:u.version||"",url:u.url||"",command:u.command||"",args:u.args||[],env:$e(u.env),headers:e,disabledTools:n,toolPatches:y,namespace:u.namespace||"",extraConfig:b,rootExtra:O,configStr:JSON.stringify(u,null,2),disabled:!!u.disabled}}function He(){const u={...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"?(u.package=r.value.package,u.version=r.value.version||void 0):r.value.type==="url"?u.url=r.value.url:r.value.type==="stdio"&&(u.command=r.value.command,u.args=r.value.args);const e={...r.value.extraConfig};return r.value.disabledTools.length>0&&(e.disabledTools=r.value.disabledTools),r.value.headers.length>0&&(e.headers=Oe(r.value.headers)),U.value.length>0&&(e.tools=U.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&&(u.config=e),JSON.parse(JSON.stringify(u))}xe(T,u=>{var e;if(j.value==="config"){if(u==="json")try{const n=He();(e=Z.value)!=null&&e.id&&(n.id=Z.value.id),r.value.configStr=JSON.stringify(n,null,2)}catch(n){console.error(n)}else if(u==="form")try{const n=JSON.parse(r.value.configStr);Ae(n)}catch{d.error("JSON 格式错误,忽略更改")}}});async function S(u){var e;Z.value=u,j.value="config",T.value="form",Ae(u),U.value=[],B.value="",Y.value.clear(),he.value=null,ke.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=u.config)==null?void 0:e.toolPatches,null,2)),await Fe(u.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)),h.value=!0}async function Fe(u,e=!1){var n,y,v,f,$,x,b,oe;try{const O=await de.get(`/configs/component-tools/${u}`);if(O.data.success&&O.data.data.tools&&O.data.data.tools.length>0){const A=s.config.components.find(k=>k.id===u),se=e?((n=A==null?void 0:A.config)==null?void 0:n.toolPatches)||{}:{},ne=Array.isArray((y=A==null?void 0:A.config)==null?void 0:y.disabledTools)?A.config.disabledTools:[],z={};U.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 be=se[Q];be&&be.description!==void 0&&be.description!==null&&be.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 be=se[Q];be.inputSchema&&(me={...me,...be.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:((v=A==null?void 0:A.config)==null?void 0:v.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((f=A==null?void 0:A.config)==null?void 0:f.toolPatches,null,2));const W={},le=new Set(U.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)?(W[k]=ae[k],console.log(`[loadComponentTools] 保留 toolPatch: ${k}`)):console.log(`[loadComponentTools] 过滤掉 toolPatch: ${k} (不在当前工具列表中)`)}),A&&(e||Object.keys(W).length>0)&&(A.config?A.config.toolPatches=W:A.config={toolPatches:W}),r.value.toolPatches=JSON.parse(JSON.stringify(W)),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===u);if(!O){U.value=[];return}const A=await de.post("/configs/component-tools/load",{componentId:u});if(A.data.success&&A.data.data.tools){const se=e?((x=O.config)==null?void 0:x.toolPatches)||{}:{},ne=Array.isArray((b=O.config)==null?void 0:b.disabledTools)?O.config.disabledTools:[],z={};U.value=A.data.data.tools.map(k=>{const Q=k.originalToolName||(()=>{const be=k.name.split("_");return be.length>1?be.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 be=se[Q];be.inputSchema&&(me={...me,...be.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 W={},le=new Set(U.value.map(k=>k.originalToolName));Object.keys(ae).forEach(k=>{le.has(k)&&(W[k]=ae[k])}),e&&O&&(O.config?O.config.toolPatches=W:O.config={toolPatches:W}),r.value.toolPatches=JSON.parse(JSON.stringify(W)),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 U.value=[]}catch(O){console.warn("从 MCP 组件加载工具列表失败:",O),U.value=[]}}function Ie(u){const e=s.config.components.filter(n=>n.id!==u);i("update",{components:e})}async function Tt(u){var e,n,y;F.value[u.id]=!0;try{const v=await de.post("/configs/sync-tools",{componentId:u.id});if(v.data.success)if(v.data.data.errors&&v.data.data.errors.length>0)d.error(`同步工具失败: ${v.data.data.errors.join("; ")}`);else if(v.data.data.success>0){d.success(`工具同步成功:${v.data.data.success} 个工具已更新`),v.data.data.failed>0&&d.warning(`${v.data.data.failed} 个工具同步失败`);try{const f=await de.get(`/configs/component-tools/${u.id}`);if(f.data.success&&f.data.data.tools){const $=f.data.data.tools.length,x=[...s.config.components],b=x.findIndex(oe=>oe.id===u.id);b!==-1&&(x[b]={...x[b],config:{...x[b].config,toolCount:$}},i("update",{components:x}))}}catch(f){console.warn("更新组件工具总数失败:",f)}((e=Z.value)==null?void 0:e.id)===u.id&&await Fe(u.id,!0)}else d.warning("没有工具需要同步");else d.error(`同步工具失败: ${v.data.error||"未知错误"}`)}catch(v){d.error(`同步工具失败: ${((y=(n=v.response)==null?void 0:n.data)==null?void 0:y.error)||v.message}`)}finally{F.value[u.id]=!1}}async function ut(){var u,e;if(!Z.value){d.warning("请先选择要编辑的组件");return}R.value=!0,B.value="";try{const n=await de.post("/configs/sync-tools",{componentId:Z.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(Z.value.id,!0)):d.warning("没有工具需要同步"):(B.value=n.data.error||"同步失败",d.error(`同步工具失败: ${B.value}`))}catch(n){B.value=((e=(u=n.response)==null?void 0:u.data)==null?void 0:e.error)||n.message,d.error(`同步工具失败: ${B.value}`)}finally{R.value=!1}}function ct(u){var n,y,v;const e=((n=u.config)==null?void 0:n.toolCount)??((v=(y=u.config)==null?void 0:y.tools)==null?void 0:v.length);return e!=null&&e>0?e:null}function dt(u){var y,v,f,$,x;const e=((y=u.config)==null?void 0:y.toolCount)??((f=(v=u.config)==null?void 0:v.tools)==null?void 0:f.length),n=((x=($=u.config)==null?void 0:$.disabledTools)==null?void 0:x.length)||0;if(e!=null&&e>0){const b=Math.max(0,e-n);return b>0?b:null}return null}function St(u){const e=u.originalToolName||u.name;return r.value.disabledTools.includes(e)}function $t(u,e){const n=u.originalToolName||u.name;e?r.value.disabledTools=r.value.disabledTools.filter(y=>y!==n):r.value.disabledTools.includes(n)||r.value.disabledTools.push(n)}function Qe(){r.value.disabledTools=[],d.success("已全选所有工具")}function Pt(){const u=U.value.map(n=>n.originalToolName||n.name),e=new Set(r.value.disabledTools);r.value.disabledTools=u.filter(n=>!e.has(n)),d.success("已反选工具")}function Se(u){return u.originalToolName||u.name}function Ke(u){return Ne.value[u.name]||"暂无描述"}function pt(u,e,n){var O,A,se,ne;fe.value;const y=Se(u),v=r.value.toolPatches,f=D.value,$=v[y],x=f[y],b=(O=$==null?void 0:$.fieldDescriptions)==null?void 0:O[e];return b!=null&&b!==""?b:((ne=(se=(A=x==null?void 0:x.inputSchema)==null?void 0:A.properties)==null?void 0:se[e])==null?void 0:ne.description)||"暂无描述"}function gt(u){var f;const e=Se(u),n=r.value.toolPatches[e],y=n==null?void 0:n.description;if(y==null||y==="")return!1;const v=((f=D.value[e])==null?void 0:f.description)||u.description||"暂无描述";return console.log(`[hasCustomDescription] Tool ${e}:`,{hasCustomDescription:!!y,customDescription:y==null?void 0:y.trim(),originalDescription:v==null?void 0:v.trim(),areDifferent:(y==null?void 0:y.trim())!==(v==null?void 0:v.trim()),toolPatches:r.value.toolPatches[e],originalTools:D.value[e],formToolPatches:r.value.toolPatches,allOriginalTools:D.value,toolKey:e,toolName:u.name,toolOriginalToolName:u.originalToolName}),!D.value[e]&&y?(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 Xe(u,e){var $,x,b,oe,O,A,se,ne,z,ae,W,le,k;const n=Se(u),y=r.value.toolPatches[n],v=($=y==null?void 0:y.fieldDescriptions)==null?void 0:$[e];if(v==null||v==="")return!1;const f=((O=(oe=(b=(x=D.value[n])==null?void 0:x.inputSchema)==null?void 0:b.properties)==null?void 0:oe[e])==null?void 0:O.description)||((ne=(se=(A=u.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:!!v,customDescription:v==null?void 0:v.trim(),originalDescription:f==null?void 0:f.trim(),areDifferent:(v==null?void 0:v.trim())!==(f==null?void 0:f.trim()),fieldPatches:(z=y==null?void 0:y.fieldDescriptions)==null?void 0:z[e],originalFieldDesc:(k=(le=(W=(ae=D.value[n])==null?void 0:ae.inputSchema)==null?void 0:W.properties)==null?void 0:le[e])==null?void 0:k.description,hasOriginalTool:!!D.value[n],toolKey:n,toolName:u.name,toolOriginalToolName:u.originalToolName}),!D.value[n]&&v?(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 mt(u,e,n,y){var v,f,$,x,b,oe;if(e==="tool"){he.value=u,ke.value=null;const O=U.value.find(A=>A.name===u);pe.value=Ke(O),qe.value="tool",Te.value=Se(O)}else{ke.value=u,he.value=null;const O=U.value.find(A=>A.name===n);if(O&&((f=(v=O.inputSchema)==null?void 0:v.properties)!=null&&f[y])){const A=O?Se(O):"";(oe=(b=(x=($=D.value[A])==null?void 0:$.inputSchema)==null?void 0:x.properties)==null?void 0:b[y])!=null&&oe.description||O.inputSchema.properties[y].description,pe.value=pt(O,y)}else pe.value="";qe.value="field",Te.value=O?Se(O):n||"",je.value=y||""}}function Be(u,e,n,y){var v,f,$,x,b,oe,O,A,se;if(e==="tool"){const ne=U.value.find(le=>le.name===u),z=ne?Se(ne):u,ae=((v=D.value[z])==null?void 0:v.description)||(ne==null?void 0:ne.description)||"暂无描述",W=pe.value.trim();W===ae.trim()||W===""?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=W),he.value=null,d.success("工具描述已保存")}else{const ne=U.value.find(k=>k.name===n),z=ne?Se(ne):n||Te.value,ae=y||je.value,W=((b=(x=($=(f=D.value[z])==null?void 0:f.inputSchema)==null?void 0:$.properties)==null?void 0:x[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===W.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),ke.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 m(){he.value=null,ke.value=null,pe.value="",Te.value="",je.value=""}async function a(u,e,n,y){var v,f,$,x,b,oe,O,A,se,ne,z;if(e==="tool"){const ae=U.value.find(le=>le.name===u),W=ae?Se(ae):u;if(r.value.toolPatches[W]){const le=r.value.toolPatches,k={};Object.keys(le).forEach(Q=>{if(Q!==W)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:",W),console.log("[resetDescription-tool] 还原后的 patch:",r.value.toolPatches[W]),console.log("[resetDescription-tool] originalTools:",JSON.stringify(D.value[W],null,2)),console.log("[resetDescription-tool] toolDescriptionsMap 值:",Ne.value[ae.name]),d.success("工具描述已还原")}}else{const ae=U.value.find(k=>k.name===n),W=ae?Se(ae):n||Te.value,le=y||je.value;if((v=r.value.toolPatches[W])!=null&&v.fieldDescriptions){const k=r.value.toolPatches,Q={};Object.keys(k).forEach(tt=>{if(tt!==W)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:",W),console.log("[resetDescription-field] actualFieldName:",le),console.log("[resetDescription-field] 还原后的 patch:",r.value.toolPatches[W]),console.log("[resetDescription-field] 还原后的 patch.fieldDescriptions:",(f=r.value.toolPatches[W])==null?void 0:f.fieldDescriptions),console.log("[resetDescription-field] originalTools:",JSON.stringify(D.value[W],null,2)),console.log("[resetDescription-field] originalTools 字段描述:",(oe=(b=(x=($=D.value[W])==null?void 0:$.inputSchema)==null?void 0:x.properties)==null?void 0:b[le])==null?void 0:oe.description),await Le();const me=r.value.toolPatches[W],be=(O=me==null?void 0:me.fieldDescriptions)==null?void 0:O[le],uo=((z=(ne=(se=(A=D.value[W])==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] 字段描述是否已删除:",be===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 w(u){Y.value.has(u)?Y.value.delete(u):(Y.value.clear(),Y.value.add(u))}const G=N(null),re=N(""),Ce=N("{}");function ge(){if(G.value)try{const u=JSON.parse(Ce.value);r.value.toolPatches[G.value.name]||(r.value.toolPatches[G.value.name]={}),r.value.toolPatches[G.value.name].description=re.value||void 0,r.value.toolPatches[G.value.name].inputSchema=u,d.success("Schema 修改已保存"),j.value="tools"}catch{d.error("JSON Schema 格式错误")}}async function ye(){var u,e,n,y;try{if(j.value==="config"&&T.value==="json")try{const x=JSON.parse(r.value.configStr||"{}");Ae(x)}catch{throw new Error("配置 JSON 格式错误")}if(await((u=ee.value)==null?void 0:u.validate()),M.value=!0,U.value.length===0)try{const x={id:((e=Z.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"?(x.package=r.value.package,x.version=r.value.version):r.value.type==="url"?x.url=r.value.url:r.value.type==="stdio"&&(x.command=r.value.command,x.args=r.value.args);const b=await de.post("/mcp/inspect",x);U.value=b.data.data.tools||[],U.value.length>0&&d.info(`自动获取到 ${U.value.length} 个工具`)}catch(x){console.warn("自动获取工具列表失败:",x)}console.log("保存前的 toolPatches:",JSON.stringify(r.value.toolPatches,null,2));const v=He();v.id=((n=Z.value)==null?void 0:n.id)||ot(),console.log("保存的组件配置:",JSON.stringify(v,null,2)),console.log("组件 config.toolPatches:",JSON.stringify((y=v.config)==null?void 0:y.toolPatches,null,2));const f=[...s.config.components],$=f.findIndex(x=>x.id===v.id);$!==-1?f[$]=v:f.push(v),i("update",{components:f}),h.value=!1,et()}catch(v){console.error("保存错误:",v),d.error(v.message)}finally{M.value=!1}}async function ze(){var u,e;C.value=!0,E.value={current:0,total:0,currentComponent:""};try{let n=[],y=[];if(K.value.trim()){const f=JSON.parse(K.value).mcpServers||{};y=Object.entries(f),E.value.total=y.length;for(let $=0;$<y.length;$++){const[x,b]=y[$];E.value.current=$+1,E.value.currentComponent=x;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:x,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(`[导入] 组件 ${x} 解析到 ${z.length} 个工具`))}catch(se){console.warn(`[导入] 组件 ${x} 获取工具列表失败:`,se)}n.push(A)}}else if(I.value.trim()){const v=JSON.parse(I.value),f=Array.isArray(v)?v:v.components;E.value.total=f.length;for(let $=0;$<f.length;$++){const x=f[$];E.value.current=$+1,E.value.currentComponent=x.name||`组件 ${$+1}`;const b={...x,id:ot()};if(!((u=b.config)!=null&&u.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(v=>setTimeout(v,800)),n.length>0){E.value.total=n.length,E.value.current=0;let v=0,f=0;for(let $=0;$<n.length;$++){const x=n[$];E.value.current=$+1,E.value.currentComponent=`正在同步工具: ${x.name}`;try{const b=await de.post("/configs/sync-tools",{componentId:x.id});b.data.success?b.data.data.errors&&b.data.data.errors.length>0?(f++,console.warn(`[导入] 组件 ${x.name} 同步工具失败:`,b.data.data.errors.join("; "))):b.data.data.success>0&&(v++,console.log(`[导入] 组件 ${x.name} 同步了 ${b.data.data.success} 个工具`)):(f++,console.warn(`[导入] 组件 ${x.name} 同步工具失败:`,b.data.error))}catch(b){f++,console.warn(`[导入] 组件 ${x.name} 同步工具失败:`,b.message||b)}}v>0?d.success(`导入成功:${n.length} 个组件已添加,${v} 个组件的工具已同步`):f>0?d.warning(`导入完成:${n.length} 个组件已添加,但工具同步失败`):d.success(`导入成功:${n.length} 个组件已添加`)}P.value=!1,K.value="",I.value=""}catch(n){d.error(`导入失败: ${n.message}`)}finally{C.value=!1,E.value={current:0,total:0,currentComponent:""}}}function Ge(){const u={};s.config.components.forEach(f=>{var x,b,oe;const $={env:f.env};if(f.type==="url")$.url=f.url,(x=f.config)!=null&&x.headers&&($.headers=f.config.headers);else{let O=f.command,A=f.args||[];f.type==="npm"&&(O="npx",A=["-y",f.package],f.version&&f.version!=="latest"&&(A[1]=`${f.package}@${f.version}`)),$.command=O,$.args=A}(b=f.config)!=null&&b.disabledTools&&($.disabledTools=f.config.disabledTools),(oe=f.config)!=null&&oe.toolPatches&&($.toolPatches=f.config.toolPatches),u[f.name]=$});const e=JSON.stringify({mcpServers:u},null,2),n=new Blob([e],{type:"application/json"}),y=URL.createObjectURL(n),v=document.createElement("a");v.href=y,v.download="cursor-mcp.json",v.click(),URL.revokeObjectURL(y),d.success("已导出 Cursor 格式配置")}function et(){Z.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",U.value=[],B.value="",he.value=null,ke.value=null,pe.value="",Te.value="",je.value=""}return xe(()=>h.value,u=>{u||et()}),(u,e)=>(_(),V("div",fn,[t.config.components&&t.config.components.length>0?(_(),V("div",hn,[g(p(q),{type:"primary",size:"large",class:"add-component-btn",onClick:e[0]||(e[0]=n=>h.value=!0)},{icon:c(()=>[...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:c(()=>[e[32]||(e[32]=J(" 添加组件 ",-1))]),_:1}),o("div",yn,[g(p(q),{size:"large",class:"secondary-btn",onClick:e[1]||(e[1]=n=>P.value=!0)},{icon:c(()=>[...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:c(()=>[e[34]||(e[34]=J(" 导入 JSON ",-1))]),_:1}),g(p(q),{size:"large",class:"secondary-btn",onClick:Ge},{icon:c(()=>[...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:c(()=>[e[36]||(e[36]=J(" 导出配置 ",-1))]),_:1})])])):ue("",!0),t.config.components&&t.config.components.length>0?(_(),V("div",wn,[g(p(go),{class:"component-list","show-divider":!1},{default:c(()=>[(_(!0),V(ht,null,yt(t.config.components,n=>(_(),_e(p(vo),{key:n.id},{default:c(()=>[o("div",bn,[o("div",kn,[o("div",Cn,[o("div",xn,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:c(()=>[J(" 命名空间:"+X(n.namespace.trim()),1)]),_:2},1024)):ue("",!0),ct(n)!==null?(_(),_e(p(st),{key:1,size:"small",type:"info"},{default:c(()=>[J(X(ct(n))+" 工具 ",1)]),_:2},1024)):ue("",!0),dt(n)!==null?(_(),_e(p(st),{key:2,size:"small",type:"success"},{default:c(()=>[J(X(dt(n))+" 可调用 ",1)]),_:2},1024)):ue("",!0)])]),o("div",Pn,[g(p(mo),{size:"small",value:!n.disabled,"onUpdate:value":y=>Ue(n,y)},{checked:c(()=>[...e[37]||(e[37]=[J("启用",-1)])]),unchecked:c(()=>[...e[38]||(e[38]=[J("禁用",-1)])]),_:1},8,["value","onUpdate:value"]),g(p(q),{size:"small",loading:F.value[n.id],onClick:y=>Tt(n),title:"同步工具配置"},{icon:c(()=>[...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:c(()=>[e[40]||(e[40]=J(" 同步工具 ",-1))]),_:1},8,["loading","onClick"]),g(p(q),{size:"small",onClick:y=>S(n)},{default:c(()=>[...e[41]||(e[41]=[J("配置",-1)])]),_:1},8,["onClick"]),g(p(q),{size:"small",type:"error",ghost:"",onClick:y=>Ie(n.id)},{default:c(()=>[...e[42]||(e[42]=[J("移除",-1)])]),_:1},8,["onClick"])])]),n.config?(_(),V("div",jn)):ue("",!0)])]),_:2},1024))),128))]),_:1})])):(_(),V("div",Nn,[o("div",On,[e[47]||(e[47]=Xt('<div class="empty-icon" data-v-f7895e4e><svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" data-v-f7895e4e><path d="M12 2L2 7l10 5 10-5-10-5z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" data-v-f7895e4e></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-f7895e4e></path></svg></div><h3 class="empty-title" data-v-f7895e4e>还没有添加 MCP 组件</h3><p class="empty-description" data-v-f7895e4e>点击上方&quot;添加组件&quot;按钮开始添加你的第一个 MCP 组件,或者使用&quot;导入 JSON&quot;快速导入配置</p>',3)),o("div",An,[g(p(q),{type:"primary",size:"large",onClick:e[2]||(e[2]=n=>h.value=!0)},{icon:c(()=>[...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:c(()=>[e[44]||(e[44]=J(" 添加组件 ",-1))]),_:1}),g(p(q),{size:"large",onClick:e[3]||(e[3]=n=>P.value=!0)},{icon:c(()=>[...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:c(()=>[e[46]||(e[46]=J(" 导入 JSON ",-1))]),_:1})])])])),g(p(bt),{show:h.value,"onUpdate:show":e[27]||(e[27]=n=>h.value=n),preset:"card",bordered:!1,class:"component-edit-modal",style:{width:"90vw",maxWidth:"1400px",height:"90vh",maxHeight:"90vh"}},{header:c(()=>[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(Z.value?"配置 MCP 组件":"添加 MCP 组件"),1),o("p",zn,X(Z.value?"修改组件配置和工具设置":"创建新的 MCP 服务组件"),1)])])]),footer:c(()=>[o("div",Ss,[g(p(q),{size:"large",onClick:e[26]||(e[26]=n=>h.value=!1)},{default:c(()=>[...e[79]||(e[79]=[J("取消",-1)])]),_:1}),g(p(q),{type:"primary",size:"large",onClick:ye},{default:c(()=>[J(X(Z.value?"保存修改":"添加组件"),1)]),_:1})])]),default:c(()=>[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:c(()=>[g(p(rt),{name:"config",tab:"基础配置"},{default:c(()=>[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:c(()=>[g(p(Bt),{value:"form"},{default:c(()=>[...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:c(()=>[...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:c(()=>[o("div",Fn,[e[54]||(e[54]=o("h4",{class:"section-title"},"基础信息",-1)),o("div",In,[g(p(ce),{path:"name"},{label:c(()=>[...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:c(()=>[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:c(()=>[...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:c(()=>[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:c(()=>[...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:c(()=>[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"?(_(),V("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:c(()=>[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:c(()=>[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"?(_(),V("div",Vn,[e[56]||(e[56]=o("h4",{class:"section-title"},"URL 配置",-1)),g(p(ce),{path:"url",label:"服务地址"},{default:c(()=>[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:c(()=>[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"?(_(),V("div",Ln,[e[57]||(e[57]=o("h4",{class:"section-title"},"Stdio 配置",-1)),g(p(ce),{path:"command",label:"执行命令"},{default:c(()=>[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:c(()=>[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:c(()=>[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:c(()=>[...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:c(()=>[e[59]||(e[59]=J(" 直接编辑组件的完整 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:c(()=>[o("div",Kn,[o("div",Gn,[g(p(Ve),{type:"info",bordered:!1,class:"tools-info-alert"},{icon:c(()=>[...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:c(()=>[e[61]||(e[61]=J(' 工具列表来自已保存的配置。您可以禁用特定工具或编辑其 Schema。点击"同步工具"可从 MCP 组件更新工具列表。双击工具描述或字段描述可进行编辑。 ',-1))]),_:1}),o("div",Wn,[g(p(q),{type:"primary",size:"large",loading:R.value,onClick:ut,class:"sync-btn"},{icon:c(()=>[...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:c(()=>[J(" "+X(R.value?"同步中...":"同步工具配置"),1)]),_:1},8,["loading"]),U.value.length>0?(_(),V("div",Zn,[g(p(q),{size:"medium",onClick:Qe,class:"batch-btn"},{default:c(()=>[...e[63]||(e[63]=[J(" 全选 ",-1)])]),_:1}),g(p(q),{size:"medium",onClick:Pt,class:"batch-btn"},{default:c(()=>[...e[64]||(e[64]=[J(" 反选 ",-1)])]),_:1})])):ue("",!0)])]),U.value.length>0?(_(),V("div",Yn,[o("div",Qn,[(_(!0),V(ht,null,yt(U.value,n=>(_(),V("div",{key:n.name,class:Ee(["tool-card",{"tool-expanded":Y.value.has(n.name)}]),onClick:y=>w(n.name)},[o("div",es,[o("div",ts,[g(p(no),{checked:!St(n),onClick:e[16]||(e[16]=Me(()=>{},["stop"])),"onUpdate:checked":y=>$t(n,y),size:"large"},null,8,["checked","onUpdate:checked"])]),o("div",os,[g(p(ho),{trigger:"hover","show-arrow":!0,placement:"top"},{trigger:c(()=>[o("h5",{class:"tool-name",title:Ke(n)},X(n.originalToolName||n.name),9,ns)]),default:c(()=>[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:c(()=>{var y;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?(_(),V("div",{onDblclick:Me(v=>mt(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]=v=>pe.value=v),type:"textarea",rows:3,onBlur:v=>Be(n.name,"tool"),onKeydown:[vt(Me(v=>Be(n.name,"tool"),["ctrl"]),["enter"]),vt(m,["esc"])],class:"description-input",placeholder:"输入工具描述",onClick:e[18]||(e[18]=Me(()=>{},["stop"]))},null,8,["value","onBlur","onKeydown"])),gt(n)&&he.value!==n.name?(_(),V("div",is,[e[67]||(e[67]=o("span",{class:"custom-badge",title:"已自定义描述"},"已修改",-1)),g(p(q),{text:"",size:"small",onClick:Me(v=>a(n.name,"tool"),["stop"]),class:"reset-btn"},{default:c(()=>[...e[66]||(e[66]=[J(" 还原 ",-1)])]),_:1},8,["onClick"])])):ue("",!0)],2)]),(y=n.inputSchema)!=null&&y.properties&&Object.keys(n.inputSchema.properties).length>0?(_(),V("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),V(ht,null,yt(n.inputSchema.properties,(v,f)=>{var $;return _(),V("div",{key:String(f),class:"param-item"},[o("div",ds,[o("span",ps,X(f),1),v.type?(_(),V("span",gs,X(v.type),1)):ue("",!0),($=n.inputSchema.required)!=null&&$.includes(String(f))?(_(),V("span",ms,"必填")):ue("",!0)]),o("div",{class:Ee(["param-description-wrapper",{"has-custom-description":Xe(n,String(f))}])},[ke.value!==`${n.name}.${String(f)}`?(_(),V("div",{class:"param-description",onDblclick:Me(x=>mt(`${n.name}.${String(f)}`,"field",n.name,String(f)),["stop"]),key:`field-desc-${n.name}-${String(f)}-${fe.value}`},X(pt(n,String(f),v.description)),41,vs)):(_(),_e(p(we),{key:1,value:pe.value,"onUpdate:value":e[19]||(e[19]=x=>pe.value=x),type:"textarea",rows:2,onBlur:x=>Be(`${n.name}.${String(f)}`,"field",n.name,String(f)),onKeydown:[vt(Me(x=>Be(`${n.name}.${String(f)}`,"field",n.name,String(f)),["ctrl"]),["enter"]),vt(m,["esc"])],class:"description-input",placeholder:"输入字段描述",onClick:e[20]||(e[20]=Me(()=>{},["stop"]))},null,8,["value","onBlur","onKeydown"])),Xe(n,String(f))&&ke.value!==`${n.name}.${String(f)}`?(_(),V("div",fs,[e[69]||(e[69]=o("span",{class:"custom-badge",title:"已自定义描述"},"已修改",-1)),g(p(q),{text:"",size:"small",onClick:Me(x=>a(`${n.name}.${String(f)}`,"field",n.name,String(f)),["stop"]),class:"reset-btn"},{default:c(()=>[...e[68]||(e[68]=[J(" 还原 ",-1)])]),_:1},8,["onClick"])])):ue("",!0)],2)])}),128))])])):(_(),V("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):(_(),V("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?(_(),V("div",ws,[g(p(Ve),{type:"error",bordered:!1},{icon:c(()=>[...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:c(()=>[...e[74]||(e[74]=[J("连接失败",-1)])]),default:c(()=>[J(" "+X(B.value),1)]),_:1})])):ue("",!0)])]),_:1}),j.value==="schema"?(_(),_e(p(rt),{key:0,name:"schema",tab:"Schema 编辑","display-directive":"show"},{default:c(()=>{var n,y;return[o("div",bs,[g(p(Ve),{type:"info",bordered:!1,class:"schema-info-alert"},{icon:c(()=>[...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:c(()=>[e[76]||(e[76]=J(" 重写工具的提示词。留空表示使用原始描述。修改后将覆盖工具的默认提示词 ",-1))]),_:1}),o("div",ks,[o("div",Cs,[o("h4",null,X((n=G.value)==null?void 0:n.name),1),o("p",xs,"原始描述: "+X((y=G.value)==null?void 0:y.description),1)]),g(p(ce),{label:"工具名称"},{default:c(()=>{var v;return[g(p(we),{value:(v=G.value)==null?void 0:v.name,disabled:""},null,8,["value"])]}),_:1}),g(p(ce),{label:"自定义描述"},{default:c(()=>[g(p(we),{value:re.value,"onUpdate:value":e[22]||(e[22]=v=>re.value=v),type:"textarea",rows:4,placeholder:"输入自定义描述(留空使用原始描述)"},null,8,["value"])]),_:1}),g(p(ce),{label:"完整 Schema (JSON)"},{default:c(()=>[g(at,{modelValue:Ce.value,"onUpdate:modelValue":e[23]||(e[23]=v=>Ce.value=v),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]=v=>j.value="tools"),size:"large"},{default:c(()=>[...e[77]||(e[77]=[J("取消",-1)])]),_:1}),g(p(q),{type:"primary",onClick:ge,size:"large"},{default:c(()=>[...e[78]||(e[78]=[J(" 保存 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:c(()=>[o("div",js,[g(p(q),{size:"large",onClick:e[29]||(e[29]=n=>P.value=!1),disabled:C.value},{default:c(()=>[...e[83]||(e[83]=[J("取消",-1)])]),_:1},8,["disabled"]),g(p(q),{type:"primary",size:"large",onClick:ze,loading:C.value},{default:c(()=>[J(X(C.value?`导入中... (${E.value.current}/${E.value.total})`:"导入"),1)]),_:1},8,["loading"])])]),default:c(()=>[g(p(Ve),{type:"info",bordered:!1,style:{"margin-bottom":"20px"}},{icon:c(()=>[...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:c(()=>[e[81]||(e[81]=J(" 粘贴 Cursor MCP 配置的 JSON(mcpServers 对象) ",-1))]),_:1}),C.value?(_(),_e(p(Ve),{key:0,type:"info",bordered:!1,style:{"margin-bottom":"20px"}},{icon:c(()=>[g(p(bo),{size:"small"})]),default:c(()=>[o("div",null,[e[82]||(e[82]=o("div",{style:{"margin-bottom":"8px"}},[o("strong",null,"正在导入组件...")],-1)),o("div",$s,[J(X(E.value.currentComponent)+" ",1),E.value.total>0?(_(),V("span",Ps," ("+X(E.value.current)+"/"+X(E.value.total)+") ",1)):ue("",!0)]),E.value.total>0?(_(),_e(p(wo),{key:0,percentage:Math.round(E.value.current/E.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"])]))}}),Or=Ft(Ns,[["__scopeId","data-v-f7895e4e"]]);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[h,j]of Object.entries(t.properties))try{const T=j,P=io(h),L=d.includes(h)?"":"?",R=Ye(T,l+" ",s+1),B=T&&typeof T=="object"&&T.description?`/** ${String(T.description).replace(/\*\//g,"* /")} */
12
+ ${l} `:"";i.push(`${B}${P}${L}: ${R};`)}catch(T){console.warn(`Failed to process property ${h}:`,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(C=>De(C.name)).join(" | ")};
16
+
17
+ `:"",h=i.map(C=>{const ie=`${wt(C.name)}TableRow`,U=C.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,ke=Y.nullable?"?":"";return` ${D}${ke}: ${he};`}).join(`
18
+ `);return`type ${ie} = {
19
+ ${U}
20
+ };
21
+ `}).join(`
22
+ `),j=i.length>0?`type TableName = ${i.map(C=>De(C.name)).join(" | ")};
23
+
24
+ `:"",T=s.length>0?`type ToolName = ${s.map(C=>{const E=C.originalToolName||C.name;return De(E)}).join(" | ")};
25
+
26
+ `:"",P=new Map;s.filter(C=>C&&C.name).forEach(C=>{try{const E=C.name||"Unknown",ie=Ye(C.inputSchema||{type:"object",properties:{}}),U=Qt(E);if(!U||U.trim()===""){console.warn(`[Context Types] Invalid type name for tool: ${E}`);return}const Y=`${U}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: ${E}`)}}catch(E){console.warn(`[Context Types] Failed to generate type for tool ${C==null?void 0:C.name}:`,E)}});const M=Array.from(P.values()).join(`
27
+ `),L=M?`${M}
28
+
29
+ `:"",R=s.filter(C=>C&&C.name).map(C=>{try{const E=C.originalToolName||C.name,ie=De(E),U=C.name||"Unknown",Y=Qt(U);if(!Y||Y.trim()==="")return console.warn(`[Context Types] Invalid type name for tool: ${U}, skipping overload`),null;const D=`${Y}Args`;return P.has(D)||console.warn(`[Context Types] Type ${D} not found in type definitions for tool: ${U}`),`${C.description?` /**
30
+ * ${C.description.replace(/\*\//g,"* /")}
31
+ *
32
+ * @param toolName - 工具名称(原始名称,不带命名空间)
33
+ * @param args - 工具参数
34
+ * @returns 工具执行结果
35
+ */
36
+ `:" "}callTool(toolName: ${ie}, args: ${D}): Promise<any>;`}catch(E){return console.warn(`Failed to generate overload for tool ${C==null?void 0:C.name}:`,E),null}}).filter(C=>C!==null).join(`
37
+ `),B=s.length>0?`${R}
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>;`,Z=l.variables.length>0?"get(name: VarName): string;":"get(name: string): string;",ee=i.map(C=>{const ie=`${wt(C.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(C.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>>>;`,I=i.map(C=>{const ie=`${wt(C.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(C.name)}, filter?: (row: ${ie}) => boolean): Promise<Array<${ie}>>;`}).join(`
111
+ `),F=i.length>0?`${I}
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}${h}${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
+ ${Z}
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
+ ${F}
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(R=>De(R.name)).join(" | ")};
333
+
334
+ `:"",h=i.length>0?`type TableName = ${i.map(R=>De(R.name)).join(" | ")};
335
+
336
+ `:"",j=s.length>0?`type ToolName = ${s.map(R=>{const B=R.originalToolName||R.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}${h}${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={viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{width:"16px",height:"16px"}},gr={class:"test-result-content"},mr={class:"test-result-pre"},vr={class:"test-result-code-inner"},fr={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
+ `,hr=Ct({__name:"CustomToolsManager",props:{config:{}},emits:["update"],setup(t,{emit:l}){const s=t,i=l,d=Jt(),h=N(!1),j=N(!1),T=N(null),P=N(),M=N(""),L=N("schema"),R=N(!1),B=N(!1),Z=N(""),ee=N(!1),K=N("{}"),I=N(null),F=N(!1),C=Pe(()=>S.value.serverScript!==Z.value),E=Pe(()=>R.value?"height: calc(100vh - 120px); border-radius: 12px; overflow: hidden;":"height: 474px; border-radius: 12px; overflow: hidden;"),ie=N([]),U=N([]),Y=m=>m?`custom_tool_script_${m}`:"custom_tool_script_new",D=m=>{const a=Y(m),w=localStorage.getItem(a);return w||null},fe=(m,a)=>{const w=Y(m);localStorage.setItem(w,a)},Ne=m=>{const a=Y(m);localStorage.removeItem(a)},he=m=>m?`custom_tool_test_args_${m}`:"custom_tool_test_args_new",ke=m=>{const a=he(m);return localStorage.getItem(a)},pe=(m,a)=>{const w=he(m);localStorage.setItem(w,a)},qe={pageSize:10,showSizePicker:!0,pageSizes:[10,20,50]},Te=m=>({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:m=>m.required?ve(Vt,{type:"error"},{default:()=>"是"}):"否"},{title:"描述",key:"description",ellipsis:{tooltip:!0}}],r=[{title:"工具名称",key:"name",width:300,render(m){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;"},m.name.charAt(0).toUpperCase()),ve("div",{style:"display: flex; flex-direction: column;"},[ve("span",{style:"font-weight: 500;"},m.name)])]);return!m.parameters||m.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:w=>w.required?ve(Vt,{type:"error"},{default:()=>"是"}):"否"},{title:"描述",key:"description"}],data:m.parameters,pagination:!1,singleLine:!1})])})])}},{title:"脚本",key:"script",width:150,render(m){return m.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:m.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(m){return ve(Co,{size:"small"},{default:()=>[ve(q,{size:"small",onClick:()=>ct(m)},{default:()=>"编辑"}),ve(q,{size:"small",type:"error",onClick:()=>dt(m.id)},{default:()=>"删除"})]})}}],H=Pe(()=>{const m=s.config.customTools.filter(w=>(w.source||"custom")==="custom");if(!M.value)return m;const a=M.value.toLowerCase();return m.filter(w=>w.name.toLowerCase().includes(a)||w.description.toLowerCase().includes(a))});async function te(){try{const m=await de.get("/configs/all-tools");m.data.success&&m.data.data.tools?ie.value=m.data.data.tools:ie.value=[]}catch(m){console.error("Failed to load MCP tools from database:",m),ie.value=[]}}async function Oe(){try{const m=await de.get("/tables/definitions");m.data.success&&(U.value=m.data.data||[])}catch(m){console.error("Failed to load tables:",m),U.value=[]}}const $e=Pe(()=>{let m=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((w,G)=>(G.name&&G.name.trim()&&(w[G.name.trim()]={type:G.type,description:G.description||""}),w),{}),required:S.value.parameters.filter(w=>w.required).map(w=>w.name.trim())}};m=m.filter(w=>w.name!==S.value.name).concat(a)}return Et({config:s.config,mcpTools:m,tables:U.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 w=a.name.trim(),re=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(w)?w:`"${w.replace(/"/g,'\\"')}"`,Ce=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}${Ce}: ${ye};`}).join(`
471
+ `)}
472
+ }
473
+ `),Ae=N(0),He=Pe(()=>[{content:$e.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 m={};return S.value.parameters.forEach(a=>{if(a.name&&a.name.trim())switch(a.type){case"number":m[a.name]=0;break;case"boolean":m[a.name]=!1;break;case"array":m[a.name]=[];break;case"object":m[a.name]={};break;default:m[a.name]=""}}),JSON.stringify(m,null,2)}function ct(m){T.value=m;const w=D(m.id)||m.serverScript||We;S.value={name:m.name,description:m.description,serverScript:w,parameters:m.parameters?JSON.parse(JSON.stringify(m.parameters)):[]},Z.value=m.serverScript||"",h.value=!0}function dt(m){const a=s.config.customTools.filter(w=>w.id!==m);i("update",{customTools:a})}async function St(){var m,a,w;try{if(await((m=P.value)==null?void 0:m.validate()),j.value=!0,!S.value.serverScript)throw new Error("脚本不能为空");const G={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:((w=T.value)==null?void 0:w.source)||"custom"},re=[...s.config.customTools],Ce=re.findIndex(ge=>ge.id===G.id);Ce!==-1?re[Ce]=G:re.push(G),i("update",{customTools:re}),Ne(G.id),Ne(null),h.value=!1,Be()}catch(G){d.error(G.message)}finally{j.value=!1}}function $t(m){var w;const a=((w=T.value)==null?void 0:w.id)||null;fe(a,m)}function Qe(){var a;Z.value=S.value.serverScript;const m=((a=T.value)==null?void 0:a.id)||null;fe(m,S.value.serverScript),d.success("脚本已保存")}async function Pt(){var m,a,w,G,re,Ce;if(!S.value.serverScript.trim()){d.warning("请先编写脚本内容"),ee.value=!1;return}Qe(),B.value=!0,I.value=null,F.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=((m=T.value)==null?void 0:m.id)||null;pe(ze,K.value);const Ge=(a=ye.data.data)==null?void 0:a.result;I.value=Ge,F.value=!0,d.success("测试执行成功")}else I.value={error:ye.data.error,success:!1},F.value=!0,d.error(`测试执行失败: ${ye.data.error}`)}catch(ge){I.value={error:((G=(w=ge.response)==null?void 0:w.data)==null?void 0:G.error)||ge.message,success:!1},F.value=!0,d.error(`测试执行失败: ${((Ce=(re=ge.response)==null?void 0:re.data)==null?void 0:Ce.error)||ge.message}`)}finally{B.value=!1}}function Se(m){try{return JSON.stringify(m,null,2)}catch{return String(m)}}function Ke(){K.value=ut(),d.info("已重置为默认参数")}function pt(){ee.value=!1,I.value=null,F.value=!1}function gt(){R.value=!R.value}function Xe(m){const a=m.match(/export\s+default\s+async\s+function\s*(\w+)?\s*\([^)]*\)\s*\{([\s\S]*)\}/);return a&&a[1]?a[1].trim():m}async function mt(){try{let m=ie.value;if(T.value&&S.value.name){const e={name:S.value.name,description:S.value.description||"",inputSchema:{type:"object",properties:S.value.parameters.reduce((n,y)=>(y.name&&y.name.trim()&&(n[y.name.trim()]={type:y.type,description:y.description||""}),n),{}),required:S.value.parameters.filter(n=>n.required).map(n=>n.name.trim())}};m=m.filter(n=>n.name!==S.value.name).concat(e)}const a=Et({config:s.config,mcpTools:m,tables:U.value}),w=Ue.value,G=S.value.parameters.filter(e=>e.name&&e.name.trim()).map(e=>`- ${e.name} (${e.type}${e.required?", required":", optional"}): ${e.description||"无描述"}`).join(`
474
+ `),re=U.value.length>0?U.value.map(e=>`- ${e.name}${e.description?`: ${e.description}`:""}`).join(`
475
+ `):"暂无可用数据表",Ce=S.value.serverScript.trim()||We,ge=Xe(Ce),ye=Xe(We),ze=Ce!==We&&ge!==ye,Ge=S.value.name||"未命名工具",et=S.value.description||"无描述",u=ze?`请帮我调整/优化以下函数的实现。工具名称:${Ge},描述:${et}。
476
+
477
+ ## 需求描述
478
+
479
+ [请在此处补充你的具体需求描述,说明需要如何调整或优化当前实现]
480
+
481
+ ## 类型定义
482
+
483
+ ### Context 类型定义
484
+
485
+ \`\`\`typescript
486
+ ${a}
487
+ \`\`\`
488
+
489
+ ### ToolArgs 类型定义
490
+
491
+ \`\`\`typescript
492
+ ${w}
493
+ \`\`\`
494
+
495
+ ## 工具参数定义
496
+
497
+ ${G||"暂无参数定义"}
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`:`请帮我实现以下函数。工具名称:${Ge},描述:${et}。
526
+
527
+ ## 需求描述
528
+
529
+ [请在此处补充你的具体需求描述]
530
+
531
+ ## 类型定义
532
+
533
+ ### Context 类型定义
534
+
535
+ \`\`\`typescript
536
+ ${a}
537
+ \`\`\`
538
+
539
+ ### ToolArgs 类型定义
540
+
541
+ \`\`\`typescript
542
+ ${w}
543
+ \`\`\`
544
+
545
+ ## 工具参数定义
546
+
547
+ ${G||"暂无参数定义"}
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(u),d.success("提示词已复制到剪贴板!")}catch(m){console.error("Failed to copy prompt:",m),d.error("复制失败,请手动复制")}}function Be(){T.value=null,L.value="schema",R.value=!1,ee.value=!1,K.value="{}",I.value=null,F.value=!1;const m=D(null);S.value={name:"",description:"",serverScript:m||We,parameters:[]},Z.value=""}return Ut(()=>{te(),Oe()}),xe(()=>s.config.components,()=>{te()},{deep:!0}),xe(()=>L.value,m=>{m==="implementation"&&Le(()=>{Ae.value++})}),xe(()=>S.value.parameters,()=>{Le(()=>{Ae.value++})},{deep:!0,immediate:!1}),xe(()=>[S.value.name,S.value.description],()=>{Le(()=>{Ae.value++})},{immediate:!1}),xe(()=>ee.value,m=>{var a;if(m){const w=((a=T.value)==null?void 0:a.id)||null,G=ke(w);G?K.value=G:K.value=ut()}}),xe(()=>s.config.customTools,()=>{te()},{deep:!0}),xe(()=>h.value,m=>{if(m){if(!T.value){const a=D(null);a&&(S.value.serverScript=a)}}else Be()}),(m,a)=>(_(),V("div",As,[o("div",Ms,[g(p(q),{type:"primary",size:"large",class:"add-tool-btn",onClick:a[0]||(a[0]=w=>h.value=!0)},{icon:c(()=>[...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:c(()=>[a[14]||(a[14]=J(" 添加工具 ",-1))]),_:1}),g(p(we),{value:M.value,"onUpdate:value":a[1]||(a[1]=w=>M.value=w),placeholder:"搜索工具名称或描述...",size:"large",clearable:"",class:"search-input"},{prefix:c(()=>[...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:h.value,"onUpdate:show":a[9]||(a[9]=w=>h.value=w),preset:"card",bordered:!1,class:"tool-edit-modal",style:{width:"90vw",maxWidth:"1400px",height:"90vh",maxHeight:"90vh"}},{header:c(()=>[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:c(()=>[o("div",er,[g(p(q),{size:"large",onClick:a[8]||(a[8]=w=>h.value=!1)},{default:c(()=>[...a[36]||(a[36]=[J("取消",-1)])]),_:1}),g(p(q),{type:"primary",size:"large",loading:j.value,onClick:St},{default:c(()=>[J(X(T.value?"保存修改":"创建工具"),1)]),_:1},8,["loading"])])]),default:c(()=>[o("div",Us,[g(p(to),{ref_key:"formRef",ref:P,model:S.value,rules:Ie,class:"tool-form"},{default:c(()=>[g(p(eo),{value:L.value,"onUpdate:value":a[7]||(a[7]=w=>L.value=w),type:"line",animated:"",size:"large",class:"tool-config-tabs"},{default:c(()=>[g(p(rt),{name:"schema",tab:"Schema 声明"},{default:c(()=>[o("div",Js,[g(p(Ve),{type:"info",bordered:!1,class:"schema-tip"},{icon:c(()=>[...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:c(()=>[a[18]||(a[18]=J(' 在 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:c(()=>[...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:c(()=>[g(p(we),{value:S.value.name,"onUpdate:value":a[2]||(a[2]=w=>S.value.name=w),placeholder:"例如: my-custom-tool",size:"large"},null,8,["value"])]),_:1}),g(p(ce),{path:"description"},{label:c(()=>[...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:c(()=>[g(p(we),{value:S.value.description,"onUpdate:value":a[3]||(a[3]=w=>S.value.description=w),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]=w=>S.value.parameters.push(Tt())),size:"medium"},{icon:c(()=>[...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:c(()=>[a[23]||(a[23]=J(" 添加参数 ",-1))]),_:1})]),o("div",Vs,[(_(!0),V(ht,null,yt(S.value.parameters,(w,G)=>(_(),V("div",{key:G,class:"parameter-card"},[o("div",Ls,[o("span",qs,"#"+X(G+1),1),g(p(q),{type:"error",text:"",size:"small",onClick:re=>S.value.parameters.splice(G,1)},{icon:c(()=>[...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:c(()=>[a[26]||(a[26]=J(" 删除 ",-1))]),_:1},8,["onClick"])]),o("div",Hs,[g(p(ce),{label:"必填",class:"required-field"},{default:c(()=>[g(p(no),{checked:w.required,"onUpdate:checked":re=>w.required=re},null,8,["checked","onUpdate:checked"])]),_:2},1024),g(p(ce),{label:"参数名",path:`parameters[${G}].name`,rule:{required:!0,message:"必填",trigger:"blur"}},{default:c(()=>[g(p(we),{value:w.name,"onUpdate:value":re=>w.name=re,placeholder:"参数名"},null,8,["value","onUpdate:value"])]),_:2},1032,["path"]),g(p(ce),{label:"类型"},{default:c(()=>[g(p(oo),{value:w.type,"onUpdate:value":re=>w.type=re,options:Fe},null,8,["value","onUpdate:value"])]),_:2},1024),g(p(ce),{label:"描述"},{default:c(()=>[g(p(we),{value:w.description,"onUpdate:value":re=>w.description=re,placeholder:"参数描述"},null,8,["value","onUpdate:value"])]),_:2},1024)])]))),128)),S.value.parameters.length===0?(_(),V("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:c(()=>[o("div",Gs,[o("div",{class:Ee(["editor-container",{fullscreen:R.value}])},[o("div",Ws,[o("div",{class:Ee(["status-dot",{unsaved:C.value,saved:!C.value}]),title:C.value?"未保存":"已保存"},null,10,Zs)]),g(p(q),{type:"default",size:"small",class:"fullscreen-btn",onClick:gt},{icon:c(()=>[R.value?(_(),V("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)])])):(_(),V("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:c(()=>[J(" "+X(R.value?"退出全屏":"全屏"),1)]),_:1}),o("div",Xs,[g(at,{modelValue:S.value.serverScript,"onUpdate:modelValue":a[5]||(a[5]=w=>S.value.serverScript=w),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(E.value)},null,8,["modelValue","extra-libs","style"])])],2),o("div",{class:Ee(["editor-actions",{"fullscreen-actions":R.value}])},[g(p(q),{type:"default",size:"small",class:"copy-prompt-btn",onClick:mt},{icon:c(()=>[...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:c(()=>[a[31]||(a[31]=J(" 复制提示词到大模型生成 ",-1))]),_:1}),g(p(q),{type:"primary",size:"small",class:"save-btn",disabled:!C.value,onClick:Qe},{icon:c(()=>[...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:c(()=>[a[33]||(a[33]=J(" 保存 (Ctrl+S) ",-1))]),_:1},8,["disabled"]),g(p(q),{type:"info",size:"small",class:"test-btn",loading:B.value,onClick:a[6]||(a[6]=w=>ee.value=!0)},{icon:c(()=>[...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:c(()=>[a[35]||(a[35]=J(" 测试执行 ",-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]=w=>ee.value=w),preset:"card",bordered:!1,class:"test-args-modal",style:_t({width:F.value?"800px":"600px"}),title:"测试执行参数"},{header:c(()=>[...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:c(()=>[o("div",fr,[g(p(q),{size:"large",onClick:pt},{default:c(()=>[...a[46]||(a[46]=[J("取消",-1)])]),_:1}),g(p(q),{type:"primary",size:"large",loading:B.value,onClick:Pt},{default:c(()=>[...a[47]||(a[47]=[J(" 执行测试 ",-1)])]),_:1},8,["loading"])])]),default:c(()=>[o("div",tr,[S.value.parameters&&S.value.parameters.length>0?(_(),V("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(w=>w.name&&w.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:Ke},{icon:c(()=>[(_(),V("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:c(()=>[a[40]||(a[40]=J(" 重置 ",-1))]),_:1})]),g(p(we),{value:K.value,"onUpdate:value":a[10]||(a[10]=w=>K.value=w),type:"textarea",placeholder:'{"param1": "value1", "param2": 123}',rows:8,autosize:{minRows:8,maxRows:12},class:"test-args-input"},null,8,["value"])]),F.value&&I.value?(_(),V("div",ir,[o("div",ur,[o("div",cr,[(_(),V("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))]),g(p(q),{size:"small",text:"",onClick:a[11]||(a[11]=w=>F.value=!1)},{icon:c(()=>[(_(),V("svg",pr,[...a[44]||(a[44]=[o("path",{d:"M18 6L6 18M6 6l12 12",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])]))]),_:1})]),o("div",gr,[o("pre",mr,[o("code",vr,X(Se(I.value)),1),a[45]||(a[45]=J(`
576
+ `,-1))])])])):ue("",!0)])]),_:1},8,["show","style"])]))}}),Ar=Ft(hr,[["__scopeId","data-v-d764a238"]]),yr={class:"init-script-editor"},wr={class:"save-status-indicator"},br=["title"],kr={key:0,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},Cr={key:1,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},xr={class:"monaco-wrapper"},Tr={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",Sr=Ct({__name:"InitScriptEditor",props:{config:{}},emits:["update"],setup(t,{emit:l}){const s=Jt(),i=t,d=l,h=N([]),j=N([]);async function T(){try{const r=await de.get("/configs/all-tools");r.data.success&&r.data.data.tools?h.value=r.data.data.tools:h.value=[]}catch(r){console.error("Failed to load MCP tools from database:",r),h.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:h.value,tables:j.value})),L=Pe(()=>[{content:M.value,filePath:"file:///init-script-context.d.ts"}]);Ut(()=>{T(),P()}),xe(()=>i.config.components,()=>{T()},{deep:!0}),xe(()=>i.config.customTools,()=>{T()},{deep:!0});function R(){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 Z(){try{localStorage.removeItem(zt)}catch(r){console.error("Failed to clear local script:",r)}}const ee=R(),K=i.config.initScript||"",F=N(ee||K||Ze),C=N(K),E=N(ee||""),ie=Pe(()=>F.value!==E.value),U=Pe(()=>E.value!==C.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;");xe(()=>i.config.initScript,(r,H)=>{const te=r||"";if(te===(H||""))return;const $e=R();if($e&&te===$e){Z(),E.value="",C.value=te,F.value=te;return}if($e&&te!==$e){Z(),E.value="",C.value=te;const Ae=te||Ze;F.value=Ae;return}if(C.value=te,!te&&C.value)return;const Ue=te||Ze;F.value=Ue,C.value=te},{immediate:!0});function Ne(r){}function he(){const r=F.value.trim()||"";B(r),E.value=r,s.success("已保存到本地 (Ctrl+S)")}async function ke(){const r=E.value.trim()||void 0;d("update",{initScript:r}),C.value=r||"",Z(),E.value=""}async function pe(){var r,H;if(!F.value.trim()){s.warning("请先编写脚本内容");return}he(),Y.value=!0;try{const te=await de.post("/configs/test-init-script",{script:F.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:h.value,tables:j.value}),H=h.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=F.value.trim()||Ze,$e=Te(Oe),Ue=Te(Ze),He=Oe!==Ze&&$e!==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
+ ${$e}
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)=>(_(),V("div",yr,[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",wr,[o("div",{class:Ee(["status-dot",{unsaved:ie.value,saved:!ie.value,"local-only":U.value&&!ie.value}]),title:ie.value?"未保存到本地":U.value?"已保存到本地,未上传":"已保存"},null,10,br)]),g(p(q),{type:"default",size:"small",class:"fullscreen-btn",onClick:qe},{icon:c(()=>[D.value?(_(),V("svg",Cr,[...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)])])):(_(),V("svg",kr,[...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:c(()=>[J(" "+X(D.value?"退出全屏":"全屏"),1)]),_:1}),o("div",xr,[g(at,{modelValue:F.value,"onUpdate:modelValue":H[0]||(H[0]=te=>F.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",Tr,[g(p(q),{type:"default",size:"small",class:"copy-prompt-btn",onClick:je},{icon:c(()=>[...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:c(()=>[H[4]||(H[4]=J(" 复制提示词到大模型生成 ",-1))]),_:1}),g(p(q),{type:"primary",size:"small",class:"upload-btn",disabled:!U.value,onClick:ke},{icon:c(()=>[...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:c(()=>[H[6]||(H[6]=J(" 上传脚本 ",-1))]),_:1},8,["disabled"]),g(p(q),{type:"info",size:"small",class:"test-btn",loading:Y.value,onClick:pe},{icon:c(()=>[...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:c(()=>[H[8]||(H[8]=J(" 测试执行 ",-1))]),_:1},8,["loading"])])],2)]))}}),Mr=Ft(Sr,[["__scopeId","data-v-515e2056"]]);export{Ar as C,Mr as I,Or as M,at as _,ot as g,Nr as p,jr as u};