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