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
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
import{b_ as qt,r as $,q as ut,o as Tt,ah as _t,w as me,c0 as V,bU as A,s as ke,c5 as ae,bW as c,c1 as o,bV as l,bs as u,c2 as Bt,l as F,F as nt,bN as at,bS as je,c7 as ee,a3 as Nt,v as jt,bm as Se,ca as $e,c4 as st,Z as Me,aI as xt,c9 as Ht,G as ne}from"./vendor-D1MaVSrs.js";import{a as re}from"./index-BBxZKz3O.js";import{u as $t,B as K,E as Kt,h as rt,r as Ge,s as Jt,F as Gt,l as Ft,m as lt,G as Zt,H as Mt,c as Ut,d as de,e as fe,p as It,I as wt,o as Re,i as Et,t as Wt,J as Qt,K as Yt,y as Xt,g as bt,j as Ot,z as At,C as eo,k as to}from"./naive-ui-C5lXjE56.js";import{_ as St}from"./_plugin-vue_export-helper-DlAUqK2U.js";import{l as oo}from"./monaco-editor-D-KqHnQ9.js";const wn=qt("config",()=>{const p=$(null),O=$(!1);async function f(){var z,S;O.value=!0;try{const L=await re.get("/configs/me");return p.value=L.data.data,p.value}catch(L){throw new Error(((S=(z=L.response)==null?void 0:z.data)==null?void 0:S.error)||"Failed to fetch config")}finally{O.value=!1}}async function h(z){var S,L;O.value=!0;try{const U=await re.get(`/configs/user/${z}`);return p.value=U.data.data,p.value}catch(U){throw new Error(((L=(S=U.response)==null?void 0:S.data)==null?void 0:L.error)||"Failed to fetch user config")}finally{O.value=!1}}async function g(z){var S,L;try{const U=await re.put("/configs/me",z);return p.value&&U.data.data?Object.assign(p.value,U.data.data):p.value=U.data.data,p.value}catch(U){throw new Error(((L=(S=U.response)==null?void 0:S.data)==null?void 0:L.error)||"Failed to update config")}finally{}}async function y(z,S){var L,U;O.value=!0;try{const j=await re.put(`/configs/user/${z}`,S);return p.value=j.data.data,p.value}catch(j){throw new Error(((U=(L=j.response)==null?void 0:L.data)==null?void 0:U.error)||"Failed to update user config")}finally{O.value=!1}}function _(z){const S={...z,variables:z.variables.map(L=>({...L,value:L.isSecret?`{{${L.name}}}`:L.value}))};return JSON.stringify(S,null,2)}function C(z){try{const S=JSON.parse(z);if(!S.name||!Array.isArray(S.components)||!Array.isArray(S.customTools))throw new Error("Invalid config format");return S}catch(S){throw new Error(`Failed to parse config: ${S.message}`)}}return{currentConfig:p,loading:O,fetchConfig:f,fetchUserConfig:h,updateConfig:g,updateUserConfig:y,exportConfig:_,importConfig:C}});function Ke(){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 Ct(p,O){const f=O.split(".");let h=p;for(const g of f){if(h==null)return;h=h[g]}return h}function so(p,O){let f=p;const h=/\{\{#if\s+([\w.]+)\}\}([\s\S]*?)(?:\{\{else\}\}([\s\S]*?))?\{\{\/if\}\}/g;f=f.replace(h,(y,_,C,z)=>{const S=Ct(O,_);return Dt(S)?C||"":z||""});const g=/\{\{#ifnot\s+([\w.]+)\}\}([\s\S]*?)(?:\{\{else\}\}([\s\S]*?))?\{\{\/ifnot\}\}/g;return f=f.replace(g,(y,_,C,z)=>{const S=Ct(O,_);return Dt(S)?z||"":C||""}),f}function no(p,O){const f=/\{\{([\w.]+)\}\}/g;return p.replace(f,(h,g)=>{const y=Ct(O,g);return y!=null?typeof y=="object"&&!(y instanceof Date)&&!Array.isArray(y)?JSON.stringify(y):y instanceof Date?y.toISOString():String(y):h})}function bn(p,O){let f=so(p,O);return f=no(f,O),f}const it=ut({__name:"MonacoEditor",props:{modelValue:{},language:{},theme:{},options:{},extraLibs:{}},emits:["update:modelValue","save","change"],setup(p,{emit:O}){const f=p,h=O,g=$();let y=null,_=null,C=null,z=!1,S=null;const L=$(new Map);function U(j){if(!_)return;L.value.forEach(H=>{H.dispose()}),L.value.clear();const Q=(f.language||"typescript")==="typescript"?_.languages.typescript.typescriptDefaults:_.languages.typescript.javascriptDefaults;Q.setDiagnosticsOptions({noSemanticValidation:!1,noSyntaxValidation:!1}),Q.setCompilerOptions({target:_.languages.typescript.ScriptTarget.ES2020,allowNonTsExtensions:!0,strict:!0}),Q.setInlayHintsOptions({includeInlayParameterNameHints:"all"}),j.forEach(H=>{const P=H.filePath||`file:///lib-${Date.now()}.d.ts`,R=Q.addExtraLib(H.content,P);L.value.set(P,R)})}return Tt(async()=>{var I,Q,H;_=await oo.init(),f.extraLibs&&U(f.extraLibs);const j=f.language||"typescript";C&&C.dispose(),C=_.languages.registerCompletionItemProvider(j,{provideCompletionItems:()=>({suggestions:[]}),triggerCharacters:['"',"'"]}),y=_.editor.create(g.value,{value:f.modelValue,language:j,theme:f.theme||"vs-dark",automaticLayout:!0,minimap:{enabled:!0},fontSize:14,tabSize:2,readOnly:!1,...f.options,quickSuggestions:{other:!0,comments:!1,strings:!0,...(I=f.options)==null?void 0:I.quickSuggestions},suggestOnTriggerCharacters:((Q=f.options)==null?void 0:Q.suggestOnTriggerCharacters)??!0,wordWrap:((H=f.options)==null?void 0:H.wordWrap)??"off"}),y.onDidChangeModelContent(P=>{var D;if(z)return;const R=y.getValue();h("update:modelValue",R),h("change",R);const b=(D=P.changes)==null?void 0:D[P.changes.length-1];b&&(b.text==='"'||b.text==="'")&&setTimeout(()=>{y&&y.trigger("","editor.action.triggerSuggest",{})},100)}),y.addCommand(_.KeyMod.CtrlCmd|_.KeyCode.KeyS,()=>{h("save")}),S=P=>{if(!(!y||!y.hasTextFocus())){if((P.metaKey||P.ctrlKey)&&P.key==="z"&&!P.shiftKey)return P.preventDefault(),P.stopPropagation(),y.trigger("","undo",{}),!1;if((P.metaKey||P.ctrlKey)&&P.key==="z"&&P.shiftKey)return P.preventDefault(),P.stopPropagation(),y.trigger("","redo",{}),!1;if((P.metaKey||P.ctrlKey)&&P.key==="y")return P.preventDefault(),P.stopPropagation(),y.trigger("","redo",{}),!1}},document.addEventListener("keydown",S,!0)}),_t(()=>{C==null||C.dispose(),y==null||y.dispose(),S&&(document.removeEventListener("keydown",S,!0),S=null)}),me(()=>f.modelValue,j=>{if(!y)return;if(y.getValue()!==j){z=!0;try{const Q=y.getModel();if(Q){const H=Q.getFullModelRange();y.executeEdits("external-update",[{range:H,text:j}]),y.pushUndoStop();const P=Q.getLineCount(),R=Q.getLineMaxColumn(P);y.setPosition({lineNumber:P,column:R})}}finally{setTimeout(()=>{z=!1},0)}}}),me(()=>f.extraLibs,(j,I)=>{if(!j||!_||!(!I||j.length!==I.length||j.some((P,R)=>{const b=I[R];return!b||P.content!==b.content||P.filePath!==b.filePath})))return;U(j);const H=y==null?void 0:y.getModel();H&&(_.editor.setModelMarkers(H,"typescript",[]),setTimeout(()=>{if(y&&H){const P=H;if(typeof P.forceTokenization=="function")try{P.forceTokenization(H.getLineCount())}catch(R){console.warn("forceTokenization failed:",R)}else{const R=H.getLanguageId();_.editor.setModelMarkers(H,R,[])}}},100))},{deep:!0,immediate:!1}),(j,I)=>(A(),V("div",{ref_key:"editorContainer",ref:g,class:"w-full h-full min-h-[400px]"},null,512))}}),ao={class:"components-manager"},ro={key:0,class:"components-toolbar"},lo={class:"toolbar-actions"},io={key:1},uo={class:"component-item"},co={class:"component-main"},po={class:"component-icon"},mo={class:"icon-circle"},go={class:"component-info"},vo={class:"component-title"},fo={class:"name"},yo={class:"component-actions"},ho={key:0,class:"component-tools"},wo={key:2,class:"empty-state"},bo={class:"empty-state-content"},ko={class:"empty-actions"},xo={class:"modal-header"},Co={class:"modal-title"},To={class:"modal-subtitle"},$o={class:"modal-content-wrapper"},So={class:"tab-pane-content"},Po={class:"mode-switcher"},No={class:"form-content"},jo={class:"form-section"},Mo={class:"form-grid"},Oo={key:0,class:"form-section"},Ao={class:"form-grid"},Do={key:1,class:"form-section"},zo={key:2,class:"form-section"},_o={class:"json-content"},Bo={class:"editor-wrapper"},Jo={class:"tab-pane-content tools-tab-content"},Fo={class:"tools-action-bar"},Uo={class:"tools-action-buttons"},Io={key:0,class:"batch-actions"},Eo={key:0,class:"tools-list-wrapper"},Vo={class:"tools-list"},Ro=["onClick"],Lo={class:"tool-header"},qo={class:"tool-checkbox"},Ho={class:"tool-info"},Ko=["title"],Go={class:"tooltip-description"},Zo={class:"tool-actions"},Wo={class:"detail-section"},Qo=["onDblclick"],Yo={key:2,class:"description-actions"},Xo={key:0,class:"detail-section"},es={class:"params-list"},ts={class:"param-header"},os={class:"param-name"},ss={key:0,class:"param-type"},ns={key:1,class:"param-required"},as=["onDblclick"],rs={key:2,class:"field-description-actions"},ls={key:1,class:"detail-section"},is={key:1,class:"tools-empty"},us={key:2,class:"tools-error"},cs={class:"modal-footer"},ds={style:{"font-size":"12px",color:"#666"}},ps={key:0},ms={class:"modal-footer"},gs=ut({__name:"MCPComponentsManager",props:{config:{}},emits:["update"],setup(p,{emit:O}){const f=p,h=O,g=$t(),y=$(!1),_=$("config"),C=$("form"),z=$(!1),S=$(!1),L=$(!1),U=$(!1),j=$(""),I=$(null),Q=$(),H=$(""),P=$(""),R=$({}),b=$(!1),D=$({current:0,total:0,currentComponent:""});function se(r){_.value=r}const B=$([]),W=$(new Set),M=$({}),ue=$(0),Ce=ke(()=>{const r=n.value.toolPatches,t=M.value,e=B.value;ue.value;const s={};return e.forEach(a=>{var d;const i=ve(a),v=r[i];v&&v.description!==void 0&&v.description!==null&&v.description!==""?s[a.name]=v.description:s[a.name]=((d=t[i])==null?void 0:d.description)||"暂无描述"}),s}),ce=$(null),ge=$(null),le=$(""),_e=$("tool"),ye=$(""),xe=$(""),n=$({name:"",type:"npm",package:"",version:"",url:"",command:"",args:[],env:[],headers:[],disabledTools:[],toolPatches:{},namespace:"",extraConfig:{},rootExtra:{},configStr:"{}",disabled:!1}),q=[{label:"NPM 包",value:"npm"},{label:"Stdio (Command)",value:"stdio"},{label:"SSE (URL)",value:"url"}],X={name:{required:!0,message:"请输入名称",trigger:"blur"},type:{required:!0,message:"请选择类型",trigger:"change"}};function we(r){const t={};return r.forEach(e=>{e.key&&(t[e.key]=e.value)}),t}function he(r){return r?Object.entries(r).map(([t,e])=>({key:t,value:e})):[]}function Oe(r,t){const e=[...f.config.components],s=e.findIndex(a=>a.id===r.id);s!==-1&&(e[s]={...r,disabled:!t},h("update",{components:e}))}function Ne(r){var w,E,G;const t=(w=r.config)!=null&&w.headers?he(r.config.headers):[],e=((E=r.config)==null?void 0:E.disabledTools)||[],s=(G=r.config)!=null&&G.toolPatches?JSON.parse(JSON.stringify(r.config.toolPatches)):{};console.log("加载时的 toolPatches:",JSON.stringify(s,null,2));const{headers:a,disabledTools:i,toolPatches:v,tools:m,...d}=r.config||{},J=["id","name","type","namespace","env","package","version","url","command","args","config","disabled"],x={};Object.keys(r).forEach(N=>{J.includes(N)||(x[N]=r[N])}),n.value={name:r.name||"",type:r.type||"npm",package:r.package||"",version:r.version||"",url:r.url||"",command:r.command||"",args:r.args||[],env:he(r.env),headers:t,disabledTools:e,toolPatches:s,namespace:r.namespace||"",extraConfig:d,rootExtra:x,configStr:JSON.stringify(r,null,2),disabled:!!r.disabled}}function Be(){const r={...n.value.rootExtra,name:n.value.name,type:n.value.type,namespace:n.value.namespace||void 0,env:n.value.env.length>0?we(n.value.env):void 0,disabled:n.value.disabled?!0:void 0};n.value.type==="npm"?(r.package=n.value.package,r.version=n.value.version||void 0):n.value.type==="url"?r.url=n.value.url:n.value.type==="stdio"&&(r.command=n.value.command,r.args=n.value.args);const t={...n.value.extraConfig};return t.disabledTools=n.value.disabledTools,n.value.headers.length>0&&(t.headers=we(n.value.headers)),B.value.length>0&&(t.tools=B.value),n.value.toolPatches&&Object.keys(n.value.toolPatches).length>0&&(t.toolPatches=JSON.parse(JSON.stringify(n.value.toolPatches))),Object.keys(t).length>0&&(r.config=t),JSON.parse(JSON.stringify(r))}me(C,r=>{var t;if(_.value==="config"){if(r==="json")try{const e=Be();(t=I.value)!=null&&t.id&&(e.id=I.value.id),n.value.configStr=JSON.stringify(e,null,2)}catch(e){console.error(e)}else if(r==="form")try{const e=JSON.parse(n.value.configStr);Ne(e)}catch{g.error("JSON 格式错误,忽略更改")}}});async function be(r){var t;I.value=r,_.value="config",C.value="form",Ne(r),B.value=[],j.value="",W.value.clear(),ce.value=null,ge.value=null,le.value="",M.value={},console.log("[editComponent] form.value.toolPatches after fillFormFromData:",JSON.stringify(n.value.toolPatches,null,2)),console.log("[editComponent] component.config?.toolPatches:",JSON.stringify((t=r.config)==null?void 0:t.toolPatches,null,2)),await Ae(r.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(M.value,null,2)),y.value=!0}async function Ae(r,t=!1){var e,s,a,i,v,m,d,J;try{const x=await re.get(`/configs/component-tools/${r}`);if(x.data.success&&x.data.data.tools&&x.data.data.tools.length>0){const w=f.config.components.find(k=>k.id===r),E=t?((e=w==null?void 0:w.config)==null?void 0:e.toolPatches)||{}:{},G=Array.isArray((s=w==null?void 0:w.config)==null?void 0:s.disabledTools)?w.config.disabledTools:[],N={};B.value=x.data.data.tools.map(k=>{const Y=k.originalToolName||k.name;if(k.originalDescription!==void 0&&k.originalInputSchema!==void 0)N[Y]={description:k.originalDescription||"",inputSchema:JSON.parse(JSON.stringify(k.originalInputSchema||{type:"object",properties:{}}))};else{const pe=E[Y];pe&&pe.description!==void 0&&pe.description!==null&&pe.description!==""?(console.warn(`[loadComponentTools] 无法获取工具 ${Y} 的原始数据,因为后端 API 没有返回 originalDescription`),M.value[Y]?N[Y]=M.value[Y]:N[Y]={description:"",inputSchema:{type:"object",properties:{}}}):N[Y]={description:k.description||"",inputSchema:JSON.parse(JSON.stringify(k.inputSchema||{type:"object",properties:{}}))}}let ie=k.inputSchema||{type:"object",properties:{}};if(t&&E[Y]){const pe=E[Y];pe.inputSchema&&(ie={...ie,...pe.inputSchema})}return{name:k.name,description:k.description||"",inputSchema:ie,disabled:G.includes(Y),originalToolName:Y}}),t&&Object.keys(M.value).forEach(k=>{N[k]||(N[k]=M.value[k])}),Object.keys(N).forEach(k=>{var Y;N[k].description===""&&((Y=M.value[k])!=null&&Y.description)&&(N[k]=M.value[k])}),M.value=N;const te=n.value.toolPatches&&Object.keys(n.value.toolPatches).length>0?n.value.toolPatches:((a=w==null?void 0:w.config)==null?void 0:a.toolPatches)||{};console.log("[loadComponentTools] existingToolPatches:",JSON.stringify(te,null,2)),console.log("[loadComponentTools] form.value.toolPatches:",JSON.stringify(n.value.toolPatches,null,2)),console.log("[loadComponentTools] component.config?.toolPatches:",JSON.stringify((i=w==null?void 0:w.config)==null?void 0:i.toolPatches,null,2));const Z={},oe=new Set(B.value.map(k=>k.originalToolName||k.name).filter(k=>k!=null&&k!==""));console.log("[loadComponentTools] currentToolNames:",Array.from(oe)),console.log("[loadComponentTools] existingToolPatches keys:",Object.keys(te)),Object.keys(te).forEach(k=>{oe.has(k)?(Z[k]=te[k],console.log(`[loadComponentTools] 保留 toolPatch: ${k}`)):console.log(`[loadComponentTools] 过滤掉 toolPatch: ${k} (不在当前工具列表中)`)}),w&&(t||Object.keys(Z).length>0)&&(w.config?w.config.toolPatches=Z:w.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(M.value,null,2));return}}catch(x){((v=x.response)==null?void 0:v.status)===404?console.log("数据库中没有工具列表,尝试从 MCP 组件加载"):console.warn("从数据库加载工具列表失败:",x)}try{const x=f.config.components.find(E=>E.id===r);if(!x){B.value=[];return}const w=await re.post("/configs/component-tools/load",{componentId:r});if(w.data.success&&w.data.data.tools){const E=t?((m=x.config)==null?void 0:m.toolPatches)||{}:{},G=Array.isArray((d=x.config)==null?void 0:d.disabledTools)?x.config.disabledTools:[],N={};B.value=w.data.data.tools.map(k=>{const Y=k.originalToolName||(()=>{const pe=k.name.split("_");return pe.length>1?pe.slice(-1)[0]:k.name})();N[Y]={description:k.description||"",inputSchema:JSON.parse(JSON.stringify(k.inputSchema||{type:"object",properties:{}}))};let ie=k.inputSchema||{type:"object",properties:{}};if(t&&E[Y]){const pe=E[Y];pe.inputSchema&&(ie={...ie,...pe.inputSchema})}return{name:k.name,description:k.description||"",inputSchema:ie,disabled:G.includes(Y),originalToolName:Y}}),t&&Object.keys(M.value).forEach(k=>{N[k]||(N[k]=M.value[k])}),M.value=N;const te=n.value.toolPatches&&Object.keys(n.value.toolPatches).length>0?n.value.toolPatches:((J=x.config)==null?void 0:J.toolPatches)||{};console.log("[loadComponentTools-from-MCP] existingToolPatches:",JSON.stringify(te,null,2));const Z={},oe=new Set(B.value.map(k=>k.originalToolName));Object.keys(te).forEach(k=>{oe.has(k)&&(Z[k]=te[k])}),t&&x&&(x.config?x.config.toolPatches=Z:x.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(M.value,null,2))}else B.value=[]}catch(x){console.warn("从 MCP 组件加载工具列表失败:",x),B.value=[]}}function T(r){const t=f.config.components.filter(e=>e.id!==r);h("update",{components:t})}async function ct(r){var t,e,s;R.value[r.id]=!0;try{const a=await re.post("/configs/sync-tools",{componentId:r.id});if(a.data.success)if(a.data.data.errors&&a.data.data.errors.length>0)g.error(`同步工具失败: ${a.data.data.errors.join("; ")}`);else if(a.data.data.success>0){g.success(`工具同步成功:${a.data.data.success} 个工具已更新`),a.data.data.failed>0&&g.warning(`${a.data.data.failed} 个工具同步失败`);try{const i=await re.get(`/configs/component-tools/${r.id}`);if(i.data.success&&i.data.data.tools){const v=i.data.data.tools.length,m=[...f.config.components],d=m.findIndex(J=>J.id===r.id);d!==-1&&(m[d]={...m[d],config:{...m[d].config,toolCount:v}},h("update",{components:m}))}}catch(i){console.warn("更新组件工具总数失败:",i)}((t=I.value)==null?void 0:t.id)===r.id&&await Ae(r.id,!0)}else g.warning("没有工具需要同步");else g.error(`同步工具失败: ${a.data.error||"未知错误"}`)}catch(a){g.error(`同步工具失败: ${((s=(e=a.response)==null?void 0:e.data)==null?void 0:s.error)||a.message}`)}finally{R.value[r.id]=!1}}async function dt(){var r,t;if(!I.value){g.warning("请先选择要编辑的组件");return}U.value=!0,j.value="";try{const e=await re.post("/configs/sync-tools",{componentId:I.value.id});e.data.success?e.data.data.errors&&e.data.data.errors.length>0?(j.value=e.data.data.errors.join("; "),g.error(`同步工具失败: ${j.value}`)):e.data.data.success>0?(g.success(`工具同步成功:${e.data.data.success} 个工具已更新`),e.data.data.failed>0&&(g.warning(`${e.data.data.failed} 个工具同步失败`),e.data.data.errors&&e.data.data.errors.length>0&&(j.value=e.data.data.errors.join("; "))),await Ae(I.value.id,!0)):g.warning("没有工具需要同步"):(j.value=e.data.error||"同步失败",g.error(`同步工具失败: ${j.value}`))}catch(e){j.value=((t=(r=e.response)==null?void 0:r.data)==null?void 0:t.error)||e.message,g.error(`同步工具失败: ${j.value}`)}finally{U.value=!1}}function Ze(r){var e,s,a;const t=((e=r.config)==null?void 0:e.toolCount)??((a=(s=r.config)==null?void 0:s.tools)==null?void 0:a.length);return t!=null&&t>0?t:null}function qe(r){var s,a,i,v,m;const t=((s=r.config)==null?void 0:s.toolCount)??((i=(a=r.config)==null?void 0:a.tools)==null?void 0:i.length),e=((m=(v=r.config)==null?void 0:v.disabledTools)==null?void 0:m.length)||0;if(t!=null&&t>0){const d=Math.max(0,t-e);return d>0?d:null}return null}function pt(r){const t=r.originalToolName||r.name;return n.value.disabledTools.includes(t)}function mt(r,t){const e=r.originalToolName||r.name;t?n.value.disabledTools=n.value.disabledTools.filter(s=>s!==e):n.value.disabledTools.includes(e)||n.value.disabledTools.push(e)}function gt(){n.value.disabledTools=[],g.success("已全选所有工具")}function Te(){const r=B.value.map(e=>e.originalToolName||e.name),t=new Set(n.value.disabledTools);n.value.disabledTools=r.filter(e=>!t.has(e)),g.success("已反选工具")}function ve(r){return r.originalToolName||r.name}function Je(r){return Ce.value[r.name]||"暂无描述"}function We(r,t,e){var x,w,E,G;ue.value;const s=ve(r),a=n.value.toolPatches,i=M.value,v=a[s],m=i[s],d=(x=v==null?void 0:v.fieldDescriptions)==null?void 0:x[t];return d!=null&&d!==""?d:((G=(E=(w=m==null?void 0:m.inputSchema)==null?void 0:w.properties)==null?void 0:E[t])==null?void 0:G.description)||"暂无描述"}function Fe(r){var i;const t=ve(r),e=n.value.toolPatches[t],s=e==null?void 0:e.description;if(s==null||s==="")return!1;const a=((i=M.value[t])==null?void 0:i.description)||r.description||"暂无描述";return console.log(`[hasCustomDescription] Tool ${t}:`,{hasCustomDescription:!!s,customDescription:s==null?void 0:s.trim(),originalDescription:a==null?void 0:a.trim(),areDifferent:(s==null?void 0:s.trim())!==(a==null?void 0:a.trim()),toolPatches:n.value.toolPatches[t],originalTools:M.value[t],formToolPatches:n.value.toolPatches,allOriginalTools:M.value,toolKey:t,toolName:r.name,toolOriginalToolName:r.originalToolName}),!M.value[t]&&s?(console.log(`[hasCustomDescription] Tool ${t}: originalTools not loaded yet, but has custom description, returning true`),!0):(console.log(`[hasCustomDescription] Tool ${t}: toolPatches 中有描述,返回 true 以显示还原按钮`),!0)}function Qe(r,t){var v,m,d,J,x,w,E,G,N,te,Z,oe,k;const e=ve(r),s=n.value.toolPatches[e],a=(v=s==null?void 0:s.fieldDescriptions)==null?void 0:v[t];if(a==null||a==="")return!1;const i=((x=(J=(d=(m=M.value[e])==null?void 0:m.inputSchema)==null?void 0:d.properties)==null?void 0:J[t])==null?void 0:x.description)||((G=(E=(w=r.inputSchema)==null?void 0:w.properties)==null?void 0:E[t])==null?void 0:G.description)||"暂无描述";return console.log(`[hasCustomFieldDescription] Tool ${e}, Field ${t}:`,{hasCustomDescription:!!a,customDescription:a==null?void 0:a.trim(),originalDescription:i==null?void 0:i.trim(),areDifferent:(a==null?void 0:a.trim())!==(i==null?void 0:i.trim()),fieldPatches:(N=s==null?void 0:s.fieldDescriptions)==null?void 0:N[t],originalFieldDesc:(k=(oe=(Z=(te=M.value[e])==null?void 0:te.inputSchema)==null?void 0:Z.properties)==null?void 0:oe[t])==null?void 0:k.description,hasOriginalTool:!!M.value[e],toolKey:e,toolName:r.name,toolOriginalToolName:r.originalToolName}),!M.value[e]&&a?(console.log(`[hasCustomFieldDescription] Tool ${e}, Field ${t}: originalTools not loaded yet, but has custom description, returning true`),!0):(console.log(`[hasCustomFieldDescription] Tool ${e}, Field ${t}: toolPatches 中有字段描述,返回 true 以显示还原按钮`),!0)}function Ue(r,t,e,s){var a,i,v,m,d,J;if(t==="tool"){ce.value=r,ge.value=null;const x=B.value.find(w=>w.name===r);le.value=Je(x),_e.value="tool",ye.value=ve(x)}else{ge.value=r,ce.value=null;const x=B.value.find(w=>w.name===e);if(x&&((i=(a=x.inputSchema)==null?void 0:a.properties)!=null&&i[s])){const w=x?ve(x):"";(J=(d=(m=(v=M.value[w])==null?void 0:v.inputSchema)==null?void 0:m.properties)==null?void 0:d[s])!=null&&J.description||x.inputSchema.properties[s].description,le.value=We(x,s)}else le.value="";_e.value="field",ye.value=x?ve(x):e||"",xe.value=s||""}}function Ie(r,t,e,s){var a,i,v,m,d,J,x,w,E;if(t==="tool"){const G=B.value.find(oe=>oe.name===r),N=G?ve(G):r,te=((a=M.value[N])==null?void 0:a.description)||(G==null?void 0:G.description)||"暂无描述",Z=le.value.trim();Z===te.trim()||Z===""?n.value.toolPatches[N]&&(delete n.value.toolPatches[N].description,Object.keys(n.value.toolPatches[N]).length===0&&delete n.value.toolPatches[N]):(n.value.toolPatches[N]||(n.value.toolPatches[N]={}),n.value.toolPatches[N].description=Z),ce.value=null,g.success("工具描述已保存")}else{const G=B.value.find(k=>k.name===e),N=G?ve(G):e||ye.value,te=s||xe.value,Z=((d=(m=(v=(i=M.value[N])==null?void 0:i.inputSchema)==null?void 0:v.properties)==null?void 0:m[te])==null?void 0:d.description)||((w=(x=(J=G==null?void 0:G.inputSchema)==null?void 0:J.properties)==null?void 0:x[te])==null?void 0:w.description)||"暂无描述",oe=le.value.trim();oe===Z.trim()||oe===""?(E=n.value.toolPatches[N])!=null&&E.fieldDescriptions&&(delete n.value.toolPatches[N].fieldDescriptions[te],Object.keys(n.value.toolPatches[N].fieldDescriptions).length===0&&delete n.value.toolPatches[N].fieldDescriptions,Object.keys(n.value.toolPatches[N]).length===0&&delete n.value.toolPatches[N]):(n.value.toolPatches[N]||(n.value.toolPatches[N]={}),n.value.toolPatches[N].fieldDescriptions||(n.value.toolPatches[N].fieldDescriptions={}),n.value.toolPatches[N].fieldDescriptions[te]=oe),ge.value=null,g.success("字段描述已保存")}le.value="",ye.value="",xe.value="",n.value.toolPatches=JSON.parse(JSON.stringify(n.value.toolPatches)),ue.value++,console.log("保存描述后的 toolPatches:",JSON.stringify(n.value.toolPatches,null,2)),Me(()=>{console.log("保存描述后 DOM 更新完成")})}function Ye(){ce.value=null,ge.value=null,le.value="",ye.value="",xe.value=""}async function Xe(r,t,e,s){var a,i,v,m,d,J,x,w,E,G,N;if(t==="tool"){const te=B.value.find(oe=>oe.name===r),Z=te?ve(te):r;if(n.value.toolPatches[Z]){const oe=n.value.toolPatches,k={};Object.keys(oe).forEach(Y=>{if(Y!==Z)k[Y]={...oe[Y]};else{const ie={...oe[Y]};delete ie.description,Object.keys(ie).length>0&&(k[Y]=ie)}}),n.value.toolPatches=k,ue.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(M.value[Z],null,2)),console.log("[resetDescription-tool] toolDescriptionsMap 值:",Ce.value[te.name]),g.success("工具描述已还原")}}else{const te=B.value.find(k=>k.name===e),Z=te?ve(te):e||ye.value,oe=s||xe.value;if((a=n.value.toolPatches[Z])!=null&&a.fieldDescriptions){const k=n.value.toolPatches,Y={};Object.keys(k).forEach(He=>{if(He!==Z)Y[He]={...k[He]};else{const De={...k[He]};if(De.fieldDescriptions){const yt={};Object.keys(De.fieldDescriptions).forEach(ht=>{ht!==oe&&(yt[ht]=De.fieldDescriptions[ht])}),Object.keys(yt).length>0?De.fieldDescriptions=yt:delete De.fieldDescriptions}Object.keys(De).length>0&&(Y[He]=De)}}),n.value.toolPatches=JSON.parse(JSON.stringify(Y)),ue.value++,console.log("[resetDescription-field] 还原后的 toolPatches:",JSON.stringify(n.value.toolPatches,null,2)),console.log("[resetDescription-field] actualToolKey:",Z),console.log("[resetDescription-field] actualFieldName:",oe),console.log("[resetDescription-field] 还原后的 patch:",n.value.toolPatches[Z]),console.log("[resetDescription-field] 还原后的 patch.fieldDescriptions:",(i=n.value.toolPatches[Z])==null?void 0:i.fieldDescriptions),console.log("[resetDescription-field] originalTools:",JSON.stringify(M.value[Z],null,2)),console.log("[resetDescription-field] originalTools 字段描述:",(J=(d=(m=(v=M.value[Z])==null?void 0:v.inputSchema)==null?void 0:m.properties)==null?void 0:d[oe])==null?void 0:J.description),await Me();const ie=n.value.toolPatches[Z],pe=(x=ie==null?void 0:ie.fieldDescriptions)==null?void 0:x[oe],Lt=((N=(G=(E=(w=M.value[Z])==null?void 0:w.inputSchema)==null?void 0:E.properties)==null?void 0:G[oe])==null?void 0:N.description)||"暂无描述";console.log("[resetDescription-field] 还原后的 patch.fieldDescriptions:",ie==null?void 0:ie.fieldDescriptions),console.log("[resetDescription-field] 字段描述是否已删除:",pe===void 0),console.log("[resetDescription-field] 期望的原始值:",Lt),ue.value++,await Me(),g.success("字段描述已还原")}}le.value="",ye.value="",xe.value="",console.log("还原描述后的 toolPatches:",JSON.stringify(n.value.toolPatches,null,2)),console.log("还原描述后的 originalTools:",JSON.stringify(M.value,null,2)),Me(()=>{console.log("DOM 更新完成,descriptionUpdateKey:",ue.value)})}function vt(r){W.value.has(r)?W.value.delete(r):(W.value.clear(),W.value.add(r))}async function et(){var r,t,e,s;try{if(_.value==="config"&&C.value==="json")try{const m=JSON.parse(n.value.configStr||"{}");Ne(m)}catch{throw new Error("配置 JSON 格式错误")}if(await((r=Q.value)==null?void 0:r.validate()),S.value=!0,B.value.length===0)try{const m={id:((t=I.value)==null?void 0:t.id)||Ke(),name:n.value.name,type:n.value.type,namespace:n.value.namespace,env:we(n.value.env),config:{headers:we(n.value.headers)}};n.value.type==="npm"?(m.package=n.value.package,m.version=n.value.version):n.value.type==="url"?m.url=n.value.url:n.value.type==="stdio"&&(m.command=n.value.command,m.args=n.value.args);const d=await re.post("/mcp/inspect",m);B.value=d.data.data.tools||[],B.value.length>0&&g.info(`自动获取到 ${B.value.length} 个工具`)}catch(m){console.warn("自动获取工具列表失败:",m)}console.log("保存前的 toolPatches:",JSON.stringify(n.value.toolPatches,null,2));const a=Be();a.id=((e=I.value)==null?void 0:e.id)||Ke(),console.log("保存的组件配置:",JSON.stringify(a,null,2)),console.log("组件 config.toolPatches:",JSON.stringify((s=a.config)==null?void 0:s.toolPatches,null,2));const i=[...f.config.components],v=i.findIndex(m=>m.id===a.id);v!==-1?i[v]=a:i.push(a),h("update",{components:i}),y.value=!1,ot()}catch(a){console.error("保存错误:",a),g.error(a.message)}finally{S.value=!1}}async function ft(){var r,t;b.value=!0,D.value={current:0,total:0,currentComponent:""};try{let e=[],s=[];if(H.value.trim()){const i=JSON.parse(H.value).mcpServers||{};s=Object.entries(i),D.value.total=s.length;for(let v=0;v<s.length;v++){const[m,d]=s[v];D.value.current=v+1,D.value.currentComponent=m;const J=!!d.url,x={headers:d.headers,disabledTools:d.disabledTools,toolPatches:d.toolPatches};d.transportType&&(x.transportType=d.transportType),d.type&&(x.type=d.type);const w={id:Ke(),name:m,type:J?"url":"stdio",url:d.url,command:d.command,args:d.args||[],env:d.env,config:x};try{const E={...w,config:{headers:d.headers||{}}},N=(await re.post("/mcp/inspect",E)).data.data.tools||[];N.length>0&&(x.tools=N,w.config=x,console.log(`[导入] 组件 ${m} 解析到 ${N.length} 个工具`))}catch(E){console.warn(`[导入] 组件 ${m} 获取工具列表失败:`,E)}e.push(w)}}else if(P.value.trim()){const a=JSON.parse(P.value),i=Array.isArray(a)?a:a.components;D.value.total=i.length;for(let v=0;v<i.length;v++){const m=i[v];D.value.current=v+1,D.value.currentComponent=m.name||`组件 ${v+1}`;const d={...m,id:Ke()};if(!((r=d.config)!=null&&r.tools)&&(d.url||d.command||d.package))try{const J={...d,config:{...d.config,headers:((t=d.config)==null?void 0:t.headers)||{}}},w=(await re.post("/mcp/inspect",J)).data.data.tools||[];w.length>0&&(d.config||(d.config={}),d.config.tools=w,console.log(`[导入] 组件 ${d.name} 解析到 ${w.length} 个工具`))}catch(J){console.warn(`[导入] 组件 ${d.name} 获取工具列表失败:`,J)}e.push(d)}}else throw new Error("请输入 JSON 内容");if(h("update",{components:[...f.config.components,...e]}),await new Promise(a=>setTimeout(a,800)),e.length>0){D.value.total=e.length,D.value.current=0;let a=0,i=0;for(let v=0;v<e.length;v++){const m=e[v];D.value.current=v+1,D.value.currentComponent=`正在同步工具: ${m.name}`;try{const d=await re.post("/configs/sync-tools",{componentId:m.id});d.data.success?d.data.data.errors&&d.data.data.errors.length>0?(i++,console.warn(`[导入] 组件 ${m.name} 同步工具失败:`,d.data.data.errors.join("; "))):d.data.data.success>0&&(a++,console.log(`[导入] 组件 ${m.name} 同步了 ${d.data.data.success} 个工具`)):(i++,console.warn(`[导入] 组件 ${m.name} 同步工具失败:`,d.data.error))}catch(d){i++,console.warn(`[导入] 组件 ${m.name} 同步工具失败:`,d.message||d)}}a>0?g.success(`导入成功:${e.length} 个组件已添加,${a} 个组件的工具已同步`):i>0?g.warning(`导入完成:${e.length} 个组件已添加,但工具同步失败`):g.success(`导入成功:${e.length} 个组件已添加`)}z.value=!1,H.value="",P.value=""}catch(e){g.error(`导入失败: ${e.message}`)}finally{b.value=!1,D.value={current:0,total:0,currentComponent:""}}}function tt(){const r={};f.config.components.forEach(i=>{var m,d,J;const v={env:i.env};if(i.type==="url")v.url=i.url,(m=i.config)!=null&&m.headers&&(v.headers=i.config.headers);else{let x=i.command,w=i.args||[];i.type==="npm"&&(x="npx",w=["-y",i.package],i.version&&i.version!=="latest"&&(w[1]=`${i.package}@${i.version}`)),v.command=x,v.args=w}(d=i.config)!=null&&d.disabledTools&&(v.disabledTools=i.config.disabledTools),(J=i.config)!=null&&J.toolPatches&&(v.toolPatches=i.config.toolPatches),r[i.name]=v});const t=JSON.stringify({mcpServers:r},null,2),e=new Blob([t],{type:"application/json"}),s=URL.createObjectURL(e),a=document.createElement("a");a.href=s,a.download="cursor-mcp.json",a.click(),URL.revokeObjectURL(s),g.success("已导出 Cursor 格式配置")}function ot(){I.value=null,n.value={name:"",type:"npm",package:"",version:"",url:"",command:"",args:[],env:[],headers:[],disabledTools:[],toolPatches:{},namespace:"",extraConfig:{},rootExtra:{},configStr:"{}",disabled:!1},_.value="config",C.value="form",B.value=[],j.value="",ce.value=null,ge.value=null,le.value="",ye.value="",xe.value=""}return me(()=>y.value,r=>{r||ot()}),(r,t)=>(A(),V("div",ao,[p.config.components&&p.config.components.length>0?(A(),V("div",ro,[c(u(K),{type:"primary",size:"large",class:"add-component-btn",onClick:t[0]||(t[0]=e=>y.value=!0)},{icon:l(()=>[...t[28]||(t[28]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M12 4v16m8-8H4",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:l(()=>[t[29]||(t[29]=F(" 添加组件 ",-1))]),_:1}),o("div",lo,[c(u(K),{size:"large",class:"secondary-btn",onClick:t[1]||(t[1]=e=>z.value=!0)},{icon:l(()=>[...t[30]||(t[30]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:l(()=>[t[31]||(t[31]=F(" 导入 JSON ",-1))]),_:1}),c(u(K),{size:"large",class:"secondary-btn",onClick:tt},{icon:l(()=>[...t[32]||(t[32]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:l(()=>[t[33]||(t[33]=F(" 导出配置 ",-1))]),_:1})])])):ae("",!0),p.config.components&&p.config.components.length>0?(A(),V("div",io,[c(u(Kt),{class:"component-list","show-divider":!1},{default:l(()=>[(A(!0),V(nt,null,at(p.config.components,e=>(A(),je(u(Gt),{key:e.id},{default:l(()=>[o("div",uo,[o("div",co,[o("div",po,[o("div",mo,ee(e.name.charAt(0).toUpperCase()),1)]),o("div",go,[o("div",vo,[o("span",fo,ee(e.name),1),e.namespace&&e.namespace.trim()!==""?(A(),je(u(Ge),{key:0,size:"small",type:"warning",style:{"margin-left":"8px"}},{default:l(()=>[F(" 命名空间:"+ee(e.namespace.trim()),1)]),_:2},1024)):ae("",!0),Ze(e)!==null?(A(),je(u(Ge),{key:1,size:"small",type:"info"},{default:l(()=>[F(ee(Ze(e))+" 工具 ",1)]),_:2},1024)):ae("",!0),qe(e)!==null?(A(),je(u(Ge),{key:2,size:"small",type:"success"},{default:l(()=>[F(ee(qe(e))+" 可调用 ",1)]),_:2},1024)):ae("",!0)])]),o("div",yo,[c(u(Jt),{size:"small",value:!e.disabled,"onUpdate:value":s=>Oe(e,s)},{checked:l(()=>[...t[34]||(t[34]=[F("启用",-1)])]),unchecked:l(()=>[...t[35]||(t[35]=[F("禁用",-1)])]),_:1},8,["value","onUpdate:value"]),c(u(K),{size:"small",loading:R.value[e.id],onClick:s=>ct(e),title:"同步工具配置"},{icon:l(()=>[...t[36]||(t[36]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M1 4v6h6M23 20v-6h-6M3.51 9a9 9 0 0114.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0020.49 15",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:l(()=>[t[37]||(t[37]=F(" 同步工具 ",-1))]),_:1},8,["loading","onClick"]),c(u(K),{size:"small",onClick:s=>be(e)},{default:l(()=>[...t[38]||(t[38]=[F("配置",-1)])]),_:1},8,["onClick"]),c(u(K),{size:"small",type:"error",ghost:"",onClick:s=>T(e.id)},{default:l(()=>[...t[39]||(t[39]=[F("移除",-1)])]),_:1},8,["onClick"])])]),e.config?(A(),V("div",ho)):ae("",!0)])]),_:2},1024))),128))]),_:1})])):(A(),V("div",wo,[o("div",bo,[t[44]||(t[44]=Bt('<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)),o("div",ko,[c(u(K),{type:"primary",size:"large",onClick:t[2]||(t[2]=e=>y.value=!0)},{icon:l(()=>[...t[40]||(t[40]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M12 4v16m8-8H4",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:l(()=>[t[41]||(t[41]=F(" 添加组件 ",-1))]),_:1}),c(u(K),{size:"large",onClick:t[3]||(t[3]=e=>z.value=!0)},{icon:l(()=>[...t[42]||(t[42]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:l(()=>[t[43]||(t[43]=F(" 导入 JSON ",-1))]),_:1})])])])),c(u(rt),{show:y.value,"onUpdate:show":t[24]||(t[24]=e=>y.value=e),preset:"card",bordered:!1,class:"component-edit-modal",style:{width:"90vw",maxWidth:"1400px",height:"90vh",maxHeight:"90vh"}},{header:l(()=>[o("div",xo,[t[45]||(t[45]=o("div",{class:"modal-icon"},[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1",stroke:"currentColor","stroke-width":"2"}),o("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1",stroke:"currentColor","stroke-width":"2"}),o("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1",stroke:"currentColor","stroke-width":"2"}),o("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1",stroke:"currentColor","stroke-width":"2"})])],-1)),o("div",null,[o("h3",Co,ee(I.value?"配置 MCP 组件":"添加 MCP 组件"),1),o("p",To,ee(I.value?"修改组件配置和工具设置":"创建新的 MCP 服务组件"),1)])])]),footer:l(()=>[o("div",cs,[c(u(K),{size:"large",onClick:t[23]||(t[23]=e=>y.value=!1)},{default:l(()=>[...t[72]||(t[72]=[F("取消",-1)])]),_:1}),c(u(K),{type:"primary",size:"large",onClick:et},{default:l(()=>[F(ee(I.value?"保存修改":"添加组件"),1)]),_:1})])]),default:l(()=>[o("div",$o,[c(u(Ft),{value:_.value,"onUpdate:value":[t[22]||(t[22]=e=>_.value=e),se],type:"line",animated:"",size:"large",class:"component-config-tabs"},{default:l(()=>[c(u(lt),{name:"config",tab:"基础配置"},{default:l(()=>[o("div",So,[o("div",Po,[c(u(Zt),{value:C.value,"onUpdate:value":t[4]||(t[4]=e=>C.value=e),size:"medium"},{default:l(()=>[c(u(Mt),{value:"form"},{default:l(()=>[...t[46]||(t[46]=[o("div",{class:"radio-btn-content"},[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})]),o("span",null,"表单模式")],-1)])]),_:1}),c(u(Mt),{value:"json"},{default:l(()=>[...t[47]||(t[47]=[o("div",{class:"radio-btn-content"},[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("polyline",{points:"16 18 22 12 16 6",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"}),o("polyline",{points:"8 6 2 12 8 18",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})]),o("span",null,"JSON 模式")],-1)])]),_:1})]),_:1},8,["value"])]),Nt(o("div",No,[c(u(Ut),{ref_key:"formRef",ref:Q,model:n.value,rules:X,"label-placement":"top",size:"large"},{default:l(()=>[o("div",jo,[t[51]||(t[51]=o("h4",{class:"section-title"},"基础信息",-1)),o("div",Mo,[c(u(de),{path:"name"},{label:l(()=>[...t[48]||(t[48]=[o("div",{class:"form-label"},[o("svg",{class:"label-icon",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})]),o("span",null,"组件名称")],-1)])]),default:l(()=>[c(u(fe),{value:n.value.name,"onUpdate:value":t[5]||(t[5]=e=>n.value.name=e),placeholder:"例如: filesystem, github"},null,8,["value"])]),_:1}),c(u(de),{path:"type"},{label:l(()=>[...t[49]||(t[49]=[o("div",{class:"form-label"},[o("svg",{class:"label-icon",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M7 21a4 4 0 01-4-4V5a2 2 0 012-2h4a2 2 0 012 2v12a4 4 0 01-4 4zm0 0h12a2 2 0 002-2v-4a2 2 0 00-2-2h-2.343M11 7.343l1.657-1.657a2 2 0 012.828 0l2.829 2.829a2 2 0 010 2.828l-8.486 8.485M7 17h.01",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})]),o("span",null,"组件类型")],-1)])]),default:l(()=>[c(u(It),{value:n.value.type,"onUpdate:value":t[6]||(t[6]=e=>n.value.type=e),options:q},null,8,["value"])]),_:1}),c(u(de),{path:"namespace"},{label:l(()=>[...t[50]||(t[50]=[o("div",{class:"form-label"},[o("svg",{class:"label-icon",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})]),o("span",null,"命名空间(可选)")],-1)])]),default:l(()=>[c(u(fe),{value:n.value.namespace,"onUpdate:value":t[7]||(t[7]=e=>n.value.namespace=e),placeholder:"用于工具名前缀"},null,8,["value"])]),_:1})])]),n.value.type==="npm"?(A(),V("div",Oo,[t[52]||(t[52]=o("h4",{class:"section-title"},"NPM 配置",-1)),o("div",Ao,[c(u(de),{path:"package",label:"NPM 包名",class:"col-span-2"},{default:l(()=>[c(u(fe),{value:n.value.package,"onUpdate:value":t[8]||(t[8]=e=>n.value.package=e),placeholder:"@modelcontextprotocol/server-filesystem"},null,8,["value"])]),_:1}),c(u(de),{path:"version",label:"版本"},{default:l(()=>[c(u(fe),{value:n.value.version,"onUpdate:value":t[9]||(t[9]=e=>n.value.version=e),placeholder:"latest"},null,8,["value"])]),_:1})])])):ae("",!0),n.value.type==="url"?(A(),V("div",Do,[t[53]||(t[53]=o("h4",{class:"section-title"},"URL 配置",-1)),c(u(de),{path:"url",label:"服务地址"},{default:l(()=>[c(u(fe),{value:n.value.url,"onUpdate:value":t[10]||(t[10]=e=>n.value.url=e),placeholder:"http://localhost:3000/mcp"},null,8,["value"])]),_:1}),c(u(de),{label:"HTTP Headers"},{default:l(()=>[c(u(wt),{value:n.value.headers,"onUpdate:value":t[11]||(t[11]=e=>n.value.headers=e),preset:"pair","key-placeholder":"Header 名称","value-placeholder":"Header 值"},null,8,["value"])]),_:1})])):ae("",!0),n.value.type==="stdio"?(A(),V("div",zo,[t[54]||(t[54]=o("h4",{class:"section-title"},"Stdio 配置",-1)),c(u(de),{path:"command",label:"执行命令"},{default:l(()=>[c(u(fe),{value:n.value.command,"onUpdate:value":t[12]||(t[12]=e=>n.value.command=e),placeholder:"node, python, uvx"},null,8,["value"])]),_:1}),c(u(de),{label:"命令行参数"},{default:l(()=>[c(u(wt),{value:n.value.args,"onUpdate:value":t[13]||(t[13]=e=>n.value.args=e),placeholder:"输入参数",min:0},null,8,["value"])]),_:1}),c(u(de),{label:"环境变量"},{default:l(()=>[c(u(wt),{value:n.value.env,"onUpdate:value":t[14]||(t[14]=e=>n.value.env=e),preset:"pair","key-placeholder":"变量名","value-placeholder":"变量值"},null,8,["value"])]),_:1})])):ae("",!0)]),_:1},8,["model"])],512),[[jt,C.value==="form"]]),Nt(o("div",_o,[c(u(Re),{type:"info",bordered:!1,class:"json-alert"},{icon:l(()=>[...t[55]||(t[55]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:l(()=>[t[56]||(t[56]=F(" 直接编辑组件的完整 JSON 配置,切换回表单模式或保存时会自动同步 ",-1))]),_:1}),o("div",Bo,[c(it,{modelValue:n.value.configStr,"onUpdate:modelValue":t[15]||(t[15]=e=>n.value.configStr=e),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,C.value==="json"]])])]),_:1}),c(u(lt),{name:"tools",tab:"工具管理"},{default:l(()=>[o("div",Jo,[o("div",Fo,[c(u(Re),{type:"info",bordered:!1,class:"tools-info-alert"},{icon:l(()=>[...t[57]||(t[57]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:l(()=>[t[58]||(t[58]=F(' 工具列表来自已保存的配置。您可以禁用特定工具或编辑其 Schema。点击"同步工具"可从 MCP 组件更新工具列表。双击工具描述或字段描述可进行编辑。 ',-1))]),_:1}),o("div",Uo,[c(u(K),{type:"primary",size:"large",loading:U.value,onClick:dt,class:"sync-btn"},{icon:l(()=>[...t[59]||(t[59]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M1 4v6h6M23 20v-6h-6M3.51 9a9 9 0 0114.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0020.49 15",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:l(()=>[F(" "+ee(U.value?"同步中...":"同步工具配置"),1)]),_:1},8,["loading"]),B.value.length>0?(A(),V("div",Io,[c(u(K),{size:"medium",onClick:gt,class:"batch-btn"},{default:l(()=>[...t[60]||(t[60]=[F(" 全选 ",-1)])]),_:1}),c(u(K),{size:"medium",onClick:Te,class:"batch-btn"},{default:l(()=>[...t[61]||(t[61]=[F(" 反选 ",-1)])]),_:1})])):ae("",!0)])]),B.value.length>0?(A(),V("div",Eo,[o("div",Vo,[(A(!0),V(nt,null,at(B.value,e=>(A(),V("div",{key:e.name,class:Se(["tool-card",{"tool-expanded":W.value.has(e.name)}]),onClick:s=>vt(e.name)},[o("div",Lo,[o("div",qo,[c(u(Et),{checked:!pt(e),onClick:t[16]||(t[16]=$e(()=>{},["stop"])),"onUpdate:checked":s=>mt(e,s),size:"large"},null,8,["checked","onUpdate:checked"])]),o("div",Ho,[c(u(Wt),{trigger:"hover","show-arrow":!0,placement:"top"},{trigger:l(()=>[o("h5",{class:"tool-name",title:Je(e)},ee(e.originalToolName||e.name),9,Ko)]),default:l(()=>[o("div",Go,ee(Je(e)),1)]),_:2},1024)]),o("div",Zo,[o("div",{class:Se(["expand-icon",{expanded:W.value.has(e.name)}])},[...t[62]||(t[62]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("polyline",{points:"6 9 12 15 18 9",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])],2)])]),c(u(Qt),{show:W.value.has(e.name)},{default:l(()=>{var s;return[o("div",{class:"tool-details",onClick:t[21]||(t[21]=$e(()=>{},["stop"]))},[o("div",Wo,[o("div",{class:Se(["detail-content",{"has-custom-description":Fe(e)}])},[ce.value!==e.name?(A(),V("div",{onDblclick:$e(a=>Ue(e.name,"tool"),["stop"]),class:"description-text-editable",key:`tool-desc-${e.name}-${ue.value}`},ee(Je(e)),41,Qo)):(A(),je(u(fe),{key:1,value:le.value,"onUpdate:value":t[17]||(t[17]=a=>le.value=a),type:"textarea",rows:3,onBlur:a=>Ie(e.name,"tool"),onKeydown:[st($e(a=>Ie(e.name,"tool"),["ctrl"]),["enter"]),st(Ye,["esc"])],class:"description-input",placeholder:"输入工具描述",onClick:t[18]||(t[18]=$e(()=>{},["stop"]))},null,8,["value","onBlur","onKeydown"])),Fe(e)&&ce.value!==e.name?(A(),V("div",Yo,[t[64]||(t[64]=o("span",{class:"custom-badge",title:"已自定义描述"},"已修改",-1)),c(u(K),{text:"",size:"small",onClick:$e(a=>Xe(e.name,"tool"),["stop"]),class:"reset-btn"},{default:l(()=>[...t[63]||(t[63]=[F(" 还原 ",-1)])]),_:1},8,["onClick"])])):ae("",!0)],2)]),(s=e.inputSchema)!=null&&s.properties&&Object.keys(e.inputSchema.properties).length>0?(A(),V("div",Xo,[t[67]||(t[67]=o("div",{class:"detail-section-header"},[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1",stroke:"currentColor","stroke-width":"2"}),o("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1",stroke:"currentColor","stroke-width":"2"}),o("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1",stroke:"currentColor","stroke-width":"2"}),o("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1",stroke:"currentColor","stroke-width":"2"})]),o("h6",null,"参数 Schema")],-1)),o("div",es,[(A(!0),V(nt,null,at(e.inputSchema.properties,(a,i)=>{var v;return A(),V("div",{key:String(i),class:"param-item"},[o("div",ts,[o("span",os,ee(i),1),a.type?(A(),V("span",ss,ee(a.type),1)):ae("",!0),(v=e.inputSchema.required)!=null&&v.includes(String(i))?(A(),V("span",ns,"必填")):ae("",!0)]),o("div",{class:Se(["param-description-wrapper",{"has-custom-description":Qe(e,String(i))}])},[ge.value!==`${e.name}.${String(i)}`?(A(),V("div",{class:"param-description",onDblclick:$e(m=>Ue(`${e.name}.${String(i)}`,"field",e.name,String(i)),["stop"]),key:`field-desc-${e.name}-${String(i)}-${ue.value}`},ee(We(e,String(i),a.description)),41,as)):(A(),je(u(fe),{key:1,value:le.value,"onUpdate:value":t[19]||(t[19]=m=>le.value=m),type:"textarea",rows:2,onBlur:m=>Ie(`${e.name}.${String(i)}`,"field",e.name,String(i)),onKeydown:[st($e(m=>Ie(`${e.name}.${String(i)}`,"field",e.name,String(i)),["ctrl"]),["enter"]),st(Ye,["esc"])],class:"description-input",placeholder:"输入字段描述",onClick:t[20]||(t[20]=$e(()=>{},["stop"]))},null,8,["value","onBlur","onKeydown"])),Qe(e,String(i))&&ge.value!==`${e.name}.${String(i)}`?(A(),V("div",rs,[t[66]||(t[66]=o("span",{class:"custom-badge",title:"已自定义描述"},"已修改",-1)),c(u(K),{text:"",size:"small",onClick:$e(m=>Xe(`${e.name}.${String(i)}`,"field",e.name,String(i)),["stop"]),class:"reset-btn"},{default:l(()=>[...t[65]||(t[65]=[F(" 还原 ",-1)])]),_:1},8,["onClick"])])):ae("",!0)],2)])}),128))])])):(A(),V("div",ls,[...t[68]||(t[68]=[o("div",{class:"empty-params"},[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"2"}),o("path",{d:"M12 16v-4m0-4h.01",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round"})]),o("p",null,"该工具没有输入参数")],-1)])]))])]}),_:2},1032,["show"])],10,Ro))),128))])])):L.value?ae("",!0):(A(),V("div",is,[...t[69]||(t[69]=[o("div",{class:"empty-content"},[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})]),o("h4",null,"暂无工具列表"),o("p",null,'点击上方"同步工具配置"按钮从 MCP 组件获取工具列表')],-1)])])),j.value?(A(),V("div",us,[c(u(Re),{type:"error",bordered:!1},{icon:l(()=>[...t[70]||(t[70]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),header:l(()=>[...t[71]||(t[71]=[F("连接失败",-1)])]),default:l(()=>[F(" "+ee(j.value),1)]),_:1})])):ae("",!0)])]),_:1})]),_:1},8,["value"])])]),_:1},8,["show"]),c(u(rt),{show:z.value,"onUpdate:show":t[27]||(t[27]=e=>z.value=e),preset:"card",title:"导入组件 JSON",bordered:!1,class:"import-modal",style:{width:"800px",maxWidth:"90vw"}},{footer:l(()=>[o("div",ms,[c(u(K),{size:"large",onClick:t[26]||(t[26]=e=>z.value=!1),disabled:b.value},{default:l(()=>[...t[76]||(t[76]=[F("取消",-1)])]),_:1},8,["disabled"]),c(u(K),{type:"primary",size:"large",onClick:ft,loading:b.value},{default:l(()=>[F(ee(b.value?`导入中... (${D.value.current}/${D.value.total})`:"导入"),1)]),_:1},8,["loading"])])]),default:l(()=>[c(u(Re),{type:"info",bordered:!1,style:{"margin-bottom":"20px"}},{icon:l(()=>[...t[73]||(t[73]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:l(()=>[t[74]||(t[74]=F(" 粘贴 Cursor MCP 配置的 JSON(mcpServers 对象) ",-1))]),_:1}),b.value?(A(),je(u(Re),{key:0,type:"info",bordered:!1,style:{"margin-bottom":"20px"}},{icon:l(()=>[c(u(Xt),{size:"small"})]),default:l(()=>[o("div",null,[t[75]||(t[75]=o("div",{style:{"margin-bottom":"8px"}},[o("strong",null,"正在导入组件...")],-1)),o("div",ds,[F(ee(D.value.currentComponent)+" ",1),D.value.total>0?(A(),V("span",ps," ("+ee(D.value.current)+"/"+ee(D.value.total)+") ",1)):ae("",!0)]),D.value.total>0?(A(),je(u(Yt),{key:0,percentage:Math.round(D.value.current/D.value.total*100),"show-indicator":!1,style:{"margin-top":"8px"}},null,8,["percentage"])):ae("",!0)])]),_:1})):ae("",!0),c(it,{modelValue:H.value,"onUpdate:modelValue":t[25]||(t[25]=e=>H.value=e),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"])]))}}),kn=St(gs,[["__scopeId","data-v-46d5bbd7"]]);function ze(p){return!p||typeof p!="string"?"Unknown":p.split(/[^a-zA-Z0-9_$]+/).filter(f=>f.length>0).map(f=>f.split("_").filter(h=>h.length>0).map(h=>h.charAt(0).toUpperCase()+h.slice(1).toLowerCase()).join("")).join("")||"Unknown"}function zt(p){return ze(p)}function Pe(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 Le(p,O="",f=0){if(f>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<${Le(p.items,O,f+1)}>`:"any[]";case"object":if(p.properties){const h=[],g=Array.isArray(p.required)?p.required:[];for(const[y,_]of Object.entries(p.properties))try{const C=_,z=Pt(y),L=g.includes(y)?"":"?",U=Le(C,O+" ",f+1),j=C&&typeof C=="object"&&C.description?`/** ${String(C.description).replace(/\*\//g,"* /")} */
|
|
2
|
+
${O} `:"";h.push(`${j}${z}${L}: ${U};`)}catch(C){console.warn(`Failed to process property ${y}:`,C)}return h.length===0?"Record<string, any>":`{
|
|
3
|
+
${O} ${h.join(`
|
|
4
|
+
${O} `)}
|
|
5
|
+
${O}}`}return"Record<string, any>";default:return"any"}if(p.anyOf&&Array.isArray(p.anyOf)){const h=p.anyOf.map(g=>Le(g,O,f+1)).filter(g=>g&&g!=="any");return h.length>0?h.join(" | "):"any"}if(p.oneOf&&Array.isArray(p.oneOf)){const h=p.oneOf.map(g=>Le(g,O,f+1)).filter(g=>g&&g!=="any");return h.length>0?h.join(" | "):"any"}if(p.allOf&&Array.isArray(p.allOf)){const h={type:"object",properties:{},required:[]};for(const g of p.allOf)g&&typeof g=="object"&&g.properties&&(h.properties={...h.properties,...g.properties}),g&&typeof g=="object"&&Array.isArray(g.required)&&(h.required=[...h.required||[],...g.required]);return Le(h,O,f+1)}return Array.isArray(p.enum)?p.enum.map(h=>typeof h=="string"?Pe(h):JSON.stringify(h)).join(" | "):"any"}catch(h){return console.warn("Error converting JSON Schema to TypeScript:",h,p),"any"}}function Vt(p){try{const{config:O,mcpTools:f=[],tables:h=[]}=p,g=O.variables.length>0?`type VarName = ${O.variables.map(b=>Pe(b.name)).join(" | ")};
|
|
6
|
+
|
|
7
|
+
`:"",y=h.map(b=>{const se=`${ze(b.name)}TableRow`,B=b.columns.map(W=>{const M=Pt(W.name),Ce={string:"string",number:"number",boolean:"boolean",date:"string",json:"any"}[W.type]||"any",ce=W.nullable?`${Ce} | null`:Ce,ge=W.nullable?"?":"";return` ${M}${ge}: ${ce};`}).join(`
|
|
8
|
+
`);return`type ${se} = {
|
|
9
|
+
${B}
|
|
10
|
+
};
|
|
11
|
+
`}).join(`
|
|
12
|
+
`),_=h.length>0?`type TableName = ${h.map(b=>Pe(b.name)).join(" | ")};
|
|
13
|
+
|
|
14
|
+
`:"",C=f.length>0?`type ToolName = ${f.map(b=>{const D=b.originalToolName||b.name;return Pe(D)}).join(" | ")};
|
|
15
|
+
|
|
16
|
+
`:"",z=new Map;f.filter(b=>b&&b.name).forEach(b=>{try{const D=b.name||"Unknown",se=Le(b.inputSchema||{type:"object",properties:{}}),B=zt(D);if(!B||B.trim()===""){console.warn(`[Context Types] Invalid type name for tool: ${D}`);return}const W=`${B}Args`;if(!z.has(W))z.set(W,`type ${W} = ${se};`);else{const M=z.get(W);M&&M!==`type ${W} = ${se};`&&console.warn(`[Context Types] Type ${W} already exists with different definition for tool: ${D}`)}}catch(D){console.warn(`[Context Types] Failed to generate type for tool ${b==null?void 0:b.name}:`,D)}});const S=Array.from(z.values()).join(`
|
|
17
|
+
`),L=S?`${S}
|
|
18
|
+
|
|
19
|
+
`:"",U=f.filter(b=>b&&b.name).map(b=>{try{const D=b.originalToolName||b.name,se=Pe(D),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 M=`${W}Args`;return z.has(M)||console.warn(`[Context Types] Type ${M} 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: ${se}, args: ${M}): Promise<any>;`}catch(D){return console.warn(`Failed to generate overload for tool ${b==null?void 0:b.name}:`,D),null}}).filter(b=>b!==null).join(`
|
|
26
|
+
`),j=f.length>0?`${U}
|
|
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>;`,I=O.variables.length>0?"get(name: VarName): string;":"get(name: string): string;",Q=h.map(b=>{const se=`${ze(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: ${Pe(b.name)}): Promise<Array<${se}>>;`}).join(`
|
|
57
|
+
`),H=h.length>0?`${Q}
|
|
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>>>;`,P=h.map(b=>{const se=`${ze(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: ${Pe(b.name)}, filter?: (row: ${se}) => boolean): Promise<Array<${se}>>;`}).join(`
|
|
98
|
+
`),R=h.length>0?`${P}
|
|
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}${y}${_}${L}${C}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
|
+
${j}
|
|
225
|
+
listTools(): Promise<string[]>;
|
|
226
|
+
};
|
|
227
|
+
vars: {
|
|
228
|
+
${I}
|
|
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
|
+
${R}
|
|
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 Rt(p){const{tables:O=[]}=p,f="callTool(toolName: any, args: any): Promise<any>;",h=O.map(S=>{const U=`${ze(S.name)}TableRow`,j=S.columns.map(I=>{const Q=Pt(I.name),P={string:"string",number:"number",boolean:"boolean",date:"string",json:"any"}[I.type]||"any",R=I.nullable?`${P} | null`:P,b=I.nullable?"?":"";return` ${Q}${b}: ${R};`}).join(`
|
|
322
|
+
`);return`type ${U} = {
|
|
323
|
+
${j}
|
|
324
|
+
};`}).join(`
|
|
325
|
+
|
|
326
|
+
`),g=h?`${h}
|
|
327
|
+
|
|
328
|
+
`:"",y=O.map(S=>{const U=`${ze(S.name)}TableRow`;return` get(tableName: ${Pe(S.name)}): Promise<Array<${U}>>;`}).join(`
|
|
329
|
+
`),_=O.length>0?`${y}
|
|
330
|
+
get(tableName: string): Promise<Array<Record<string, any>>>;`:"get(tableName: string): Promise<Array<Record<string, any>>>;",C=O.map(S=>{const U=`${ze(S.name)}TableRow`;return` query(tableName: ${Pe(S.name)}, filter?: (row: ${U}) => boolean): Promise<Array<${U}>>;`}).join(`
|
|
331
|
+
`),z=O.length>0?`${C}
|
|
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
|
+
${f}
|
|
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
|
+
${_}
|
|
383
|
+
${z}
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
`}function vs(p){const{contextTypeDef:O,toolArgsType:f,functionBody:h,hasCustomImplementation:g,toolName:y,toolDescription:_,functionParams:C="both"}=p,z=(j=!1)=>{const I=j?h:" // 在此处实现";return C==="both"?`export default async function(args: ToolArgs, context: Context) {
|
|
387
|
+
${I}
|
|
388
|
+
}`:C==="args"?`export default async function(args: ToolArgs) {
|
|
389
|
+
${I}
|
|
390
|
+
}`:`export default async function(context: Context) {
|
|
391
|
+
${I}
|
|
392
|
+
}`},S=()=>C==="both"?"- 只能使用 args 和 context 参数中的 API":C==="args"?"- 只能使用 args 参数中的 API":"- 只允许使用 context 参数中的 API",L=()=>g?y&&_?`请帮我调整/优化以下函数的实现。工具名称:${y},描述:${_}。`:"请帮我调整/优化以下函数的实现。":y&&_?`请帮我实现以下函数。工具名称:${y},描述:${_}。`:"请帮我实现以下函数。",U=()=>{const j=[];return f&&j.push(`### ToolArgs 类型定义
|
|
393
|
+
|
|
394
|
+
\`\`\`typescript
|
|
395
|
+
${f}
|
|
396
|
+
\`\`\``),j.push(`### Context 类型定义
|
|
397
|
+
|
|
398
|
+
\`\`\`typescript
|
|
399
|
+
${O}
|
|
400
|
+
\`\`\``),j.join(`
|
|
401
|
+
|
|
402
|
+
`)};return g?`${L()}
|
|
403
|
+
|
|
404
|
+
## 类型定义
|
|
405
|
+
|
|
406
|
+
${U()}
|
|
407
|
+
|
|
408
|
+
## 当前实现
|
|
409
|
+
|
|
410
|
+
\`\`\`typescript
|
|
411
|
+
${z(!0)}
|
|
412
|
+
\`\`\`
|
|
413
|
+
|
|
414
|
+
## 输出格式
|
|
415
|
+
|
|
416
|
+
只输出以下函数定义代码(类型部分不必输出),格式如下:
|
|
417
|
+
|
|
418
|
+
\`\`\`typescript
|
|
419
|
+
${z(!1)}
|
|
420
|
+
\`\`\`
|
|
421
|
+
|
|
422
|
+
不要输出任何注释、解释文字或其他内容。
|
|
423
|
+
|
|
424
|
+
## 约束
|
|
425
|
+
|
|
426
|
+
${S()}`:`${L()}
|
|
427
|
+
|
|
428
|
+
## 类型定义
|
|
429
|
+
|
|
430
|
+
${U()}
|
|
431
|
+
|
|
432
|
+
## 函数签名
|
|
433
|
+
|
|
434
|
+
\`\`\`typescript
|
|
435
|
+
${z(!1)}
|
|
436
|
+
\`\`\`
|
|
437
|
+
|
|
438
|
+
## 输出格式
|
|
439
|
+
|
|
440
|
+
只输出以下函数定义代码(类型部分不必输出),格式如下:
|
|
441
|
+
|
|
442
|
+
\`\`\`typescript
|
|
443
|
+
${z(!1)}
|
|
444
|
+
\`\`\`
|
|
445
|
+
|
|
446
|
+
不要输出任何注释、解释文字或其他内容。
|
|
447
|
+
|
|
448
|
+
## 约束
|
|
449
|
+
|
|
450
|
+
${S()}`}const fs={class:"tools-manager"},ys={class:"tools-toolbar"},hs={class:"tools-table-container"},ws={class:"modal-header"},bs={class:"modal-title"},ks={class:"modal-subtitle"},xs={class:"modal-content-wrapper"},Cs={class:"tab-pane-content"},Ts={class:"form-section"},$s={class:"form-grid-2"},Ss={class:"form-section"},Ps={class:"section-header"},Ns={class:"parameters-list"},js={class:"parameter-header"},Ms={class:"parameter-index"},Os={class:"parameter-fields"},As={key:0,class:"empty-parameters"},Ds={class:"tab-pane-content"},zs={class:"save-status-indicator"},_s=["title"],Bs={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"},Is={class:"test-args-content"},Es={key:0,class:"test-args-parameters"},Vs={class:"parameters-header"},Rs={class:"parameters-count"},Ls={class:"test-args-input-wrapper"},qs={class:"test-args-input-header"},Hs={viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{width:"14px",height:"14px"}},Ks={key:1,class:"test-result-section"},Gs={class:"test-result-header"},Zs={class:"test-result-title"},Ws={viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{width:"18px",height:"18px","margin-right":"8px"}},Qs={class:"test-result-actions"},Ys={viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{width:"16px",height:"16px"}},Xs={viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{width:"16px",height:"16px"}},en={class:"test-result-content"},tn={class:"test-result-pre"},on={class:"test-result-code-inner"},sn={class:"modal-footer"},Ee=`/**
|
|
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
|
+
`,nn=ut({__name:"CustomToolsManager",props:{config:{}},emits:["update"],setup(p,{emit:O}){const f=p,h=O,g=$t(),y=$(!1),_=$(!1),C=$(null),z=$(),S=$(""),L=$("schema"),U=$(!1),j=$(!1),I=$(""),Q=$(!1),H=$("{}"),P=$(null),R=$(!1),b=ke(()=>T.value.serverScript!==I.value),D=ke(()=>U.value?"height: calc(100vh - 120px); border-radius: 12px; overflow: hidden;":"height: 474px; border-radius: 12px; overflow: hidden;"),se=$([]),B=$([]),W=t=>t?`custom_tool_script_${t}`:"custom_tool_script_new",M=t=>{const e=W(t),s=localStorage.getItem(e);return s||null},ue=(t,e)=>{const s=W(t);localStorage.setItem(s,e)},Ce=t=>{const e=W(t);localStorage.removeItem(e)},ce=t=>t?`custom_tool_test_args_${t}`:"custom_tool_test_args_new",ge=t=>{const e=ce(t);return localStorage.getItem(e)},le=(t,e)=>{const s=ce(t);localStorage.setItem(s,e)},_e={pageSize:10,showSizePicker:!0,pageSizes:[10,20,50]},ye=t=>({style:"cursor: pointer; transition: all 0.2s ease;",onMouseenter:e=>{e.currentTarget.style.backgroundColor="rgba(99, 102, 241, 0.04)"},onMouseleave:e=>{e.currentTarget.style.backgroundColor=""}}),xe=[{title:"参数名",key:"name",width:150},{title:"类型",key:"type",width:100},{title:"必需",key:"required",width:80,render:t=>t.required?ne(Ot,{type:"error"},{default:()=>"是"}):"否"},{title:"描述",key:"description",ellipsis:{tooltip:!0}}],n=[{title:"",key:"drag",width:50,fixed:"left",render(){return ne("div",{class:"drag-handle",style:"cursor: move; display: flex; align-items: center; justify-content: center; color: #94a3b8; padding: 8px;"},[ne("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:"width: 18px; height: 18px;"},[ne("path",{d:"M9 5h6M9 12h6M9 19h6",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})])])}},{title:"启用",key:"enabled",width:80,fixed:"left",render(t){return ne(Jt,{value:t.enabled!==!1,size:"medium",onUpdateValue:e=>gt(t.id,e)})}},{title:"工具名称",key:"name",width:300,render(t){const e=ne("div",{style:"display: flex; align-items: center; gap: 10px;"},[ne("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;"},t.name.charAt(0).toUpperCase()),ne("div",{style:"display: flex; flex-direction: column;"},[ne("span",{style:"font-weight: 500;"},t.name)])]);return!t.parameters||t.parameters.length===0?e:ne("div",{style:"display: flex; align-items: center; justify-content: space-between;"},[e,ne(At,{trigger:"hover",style:"max-width: 600px; max-height: 500px; padding: 0; overflow: hidden;"},{trigger:()=>ne(K,{size:"tiny",tertiary:!0,circle:!0,type:"info"},{default:()=>"📄"}),default:()=>ne("div",{style:"max-height: 500px; overflow-y: auto;"},[ne(bt,{size:"small",bordered:!1,columns:[{title:"参数名",key:"name",width:120},{title:"类型",key:"type",width:80},{title:"必需",key:"required",width:60,render:s=>s.required?ne(Ot,{type:"error"},{default:()=>"是"}):"否"},{title:"描述",key:"description"}],data:t.parameters,pagination:!1,singleLine:!1})])})])}},{title:"脚本",key:"script",width:150,render(t){return t.serverScript?ne(At,{trigger:"hover",placement:"right",style:"max-width: 600px; max-height: 500px; overflow: hidden;"},{trigger:()=>ne(Ge,{type:"info",size:"small",bordered:!0,style:"cursor: pointer;"},{default:()=>"Typescript"}),default:()=>ne(eo,{code:t.serverScript,language:"typescript",style:"max-height: 500px; overflow-y: auto; font-size: 12px; display: block;"})}):ne(Ge,{type:"default",size:"small",bordered:!0},{default:()=>"None"})}},{title:"描述",key:"description",ellipsis:{tooltip:!0}},{title:"操作",key:"actions",width:150,render(t){return ne(to,{size:"small"},{default:()=>[ne(K,{size:"small",onClick:()=>pt(t)},{default:()=>"编辑"}),ne(K,{size:"small",type:"error",onClick:()=>mt(t.id)},{default:()=>"删除"})]})}}],q=ke(()=>{let t=f.config.customTools.filter(s=>(s.source||"custom")==="custom");if(t=[...t].sort((s,a)=>{const i=s.order??999999,v=a.order??999999;return i-v}),!S.value)return t;const e=S.value.toLowerCase();return t.filter(s=>s.name.toLowerCase().includes(e)||s.description.toLowerCase().includes(e))}),X=$(!1),we=$(!1);async function he(){if(!X.value)try{X.value=!0;const t=await re.get("/configs/all-tools");t.data.success&&t.data.data.tools?se.value=t.data.data.tools:se.value=[]}catch(t){console.error("Failed to load MCP tools from database:",t),se.value=[]}finally{X.value=!1}}async function Oe(){if(!we.value)try{we.value=!0;const t=await re.get("/tables/definitions");t.data.success&&(B.value=t.data.data||[])}catch(t){console.error("Failed to load tables:",t),B.value=[]}finally{we.value=!1}}const Ne=ke(()=>{let t=se.value;if(C.value&&T.value.name){const e={name:T.value.name,description:T.value.description||"",inputSchema:{type:"object",properties:T.value.parameters.reduce((s,a)=>(a.name&&a.name.trim()&&(s[a.name.trim()]={type:a.type,description:a.description||""}),s),{}),required:T.value.parameters.filter(s=>s.required).map(s=>s.name.trim())}};t=t.filter(s=>s.name!==T.value.name).concat(e)}return Vt({config:f.config,mcpTools:t,tables:B.value})}),Be=ke(()=>!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(e=>e.name&&e.name.trim()).map(e=>{const s=e.name.trim(),i=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(s)?s:`"${s.replace(/"/g,'\\"')}"`,v=e.required?"":"?",m=e.description?`/** ${e.description.replace(/\*\//g,"* /")} */
|
|
478
|
+
`:"";let d="any";switch(e.type){case"string":d="string";break;case"number":d="number";break;case"boolean":d="boolean";break;case"object":d="Record<string, any>";break;case"array":d="any[]";break;default:d="any"}return`${m}${i}${v}: ${d};`}).join(`
|
|
479
|
+
`)}
|
|
480
|
+
}
|
|
481
|
+
`),be=$(0),Ae=ke(()=>[{content:Ne.value,filePath:"file:///context.d.ts"},{content:Be.value,filePath:"file:///tool-args.d.ts"}]),T=$({name:"",description:"",serverScript:Ee,parameters:[]}),ct=[{label:"string",value:"string"},{label:"number",value:"number"},{label:"boolean",value:"boolean"},{label:"object",value:"object"},{label:"array",value:"array"}],dt={name:{required:!0,message:"请输入工具名称",trigger:"blur"},description:{required:!0,message:"请输入描述",trigger:"blur"}};function Ze(){return{name:"",type:"string",description:"",required:!1}}function qe(){const t={};return T.value.parameters.forEach(e=>{if(e.name&&e.name.trim())switch(e.type){case"number":t[e.name]=0;break;case"boolean":t[e.name]=!1;break;case"array":t[e.name]=[];break;case"object":t[e.name]={};break;default:t[e.name]=""}}),JSON.stringify(t,null,2)}function pt(t){C.value=t;const s=M(t.id)||t.serverScript||Ee;T.value={name:t.name,description:t.description,serverScript:s,parameters:t.parameters?JSON.parse(JSON.stringify(t.parameters)):[]},I.value=t.serverScript||"",y.value=!0}function mt(t){const e=f.config.customTools.filter(s=>s.id!==t);h("update",{customTools:e})}function gt(t,e){const s=f.config.customTools.map(a=>a.id===t?{...a,enabled:e}:a);h("update",{customTools:s})}$(null);let Te=null;function ve(){Me(()=>{const t=document.querySelector(".modern-table .n-data-table-tbody");!t||Te||(Te=Ht.create(t,{handle:".drag-handle",animation:150,ghostClass:"sortable-ghost",chosenClass:"sortable-chosen",dragClass:"sortable-drag",onEnd:e=>{const{oldIndex:s,newIndex:a}=e;if(s===void 0||a===void 0||s===a)return;const v=[...f.config.customTools.filter(J=>(J.source||"custom")==="custom")].sort((J,x)=>{const w=J.order??999999,E=x.order??999999;return w-E}),[m]=v.splice(s,1);v.splice(a,0,m);const d=f.config.customTools.map(J=>{const x=v.findIndex(w=>w.id===J.id);return x!==-1?{...J,order:x}:J});h("update",{customTools:d})}}))})}async function Je(){var t,e,s,a,i;try{if(await((t=z.value)==null?void 0:t.validate()),_.value=!0,!T.value.serverScript)throw new Error("脚本不能为空");const v={id:((e=C.value)==null?void 0:e.id)||Ke(),name:T.value.name,description:T.value.description,serverScript:T.value.serverScript,parameters:T.value.parameters,source:((s=C.value)==null?void 0:s.source)||"custom",enabled:((a=C.value)==null?void 0:a.enabled)!==void 0?C.value.enabled:!0,order:((i=C.value)==null?void 0:i.order)!==void 0?C.value.order:f.config.customTools.filter(w=>(w.source||"custom")==="custom").reduce((w,E)=>{const G=E.order??0;return Math.max(w,G)},-1)+1},m=[...f.config.customTools],d=m.findIndex(J=>J.id===v.id);d!==-1?m[d]=v:m.push(v),h("update",{customTools:m}),Ce(v.id),Ce(null),y.value=!1,tt()}catch(v){g.error(v.message)}finally{_.value=!1}}function We(t){var s;const e=((s=C.value)==null?void 0:s.id)||null;ue(e,t)}function Fe(){var e;I.value=T.value.serverScript;const t=((e=C.value)==null?void 0:e.id)||null;ue(t,T.value.serverScript),g.success("脚本已保存")}async function Qe(){var t,e,s,a,i,v;if(!T.value.serverScript.trim()){g.warning("请先编写脚本内容"),Q.value=!1;return}Fe(),j.value=!0,P.value=null,R.value=!1;try{let m={};try{const J=H.value.trim()||"{}";if(m=JSON.parse(J),typeof m!="object"||Array.isArray(m))throw new Error("参数必须是 JSON 对象")}catch(J){g.error(`参数格式错误: ${J.message}`),j.value=!1;return}const d=await re.post("/configs/test-custom-tool",{script:T.value.serverScript,args:m,toolName:T.value.name||"test-tool"});if(d.data.success){const J=((t=C.value)==null?void 0:t.id)||null;le(J,H.value);const x=(e=d.data.data)==null?void 0:e.result;P.value=x,R.value=!0,g.success("测试执行成功")}else P.value={error:d.data.error,success:!1},R.value=!0,g.error(`测试执行失败: ${d.data.error}`)}catch(m){P.value={error:((a=(s=m.response)==null?void 0:s.data)==null?void 0:a.error)||m.message,success:!1},R.value=!0,g.error(`测试执行失败: ${((v=(i=m.response)==null?void 0:i.data)==null?void 0:v.error)||m.message}`)}finally{j.value=!1}}function Ue(t){try{return JSON.stringify(t,null,2)}catch{return String(t)}}async function Ie(){if(P.value)try{const t=Ue(P.value);await navigator.clipboard.writeText(t),g.success("测试结果已复制到剪贴板")}catch{try{const e=Ue(P.value),s=document.createElement("textarea");s.value=e,s.style.position="fixed",s.style.left="-999999px",s.style.top="-999999px",document.body.appendChild(s),s.focus(),s.select();const a=document.execCommand("copy");document.body.removeChild(s),a?g.success("测试结果已复制到剪贴板"):g.error("复制失败,请手动复制")}catch{g.error("复制失败,请手动复制")}}}function Ye(){H.value=qe(),g.info("已重置为默认参数")}function Xe(){Q.value=!1,P.value=null,R.value=!1}function vt(){U.value=!U.value}function et(t){const e=t.match(/export\s+default\s+async\s+function\s*(\w+)?\s*\([^)]*\)\s*\{([\s\S]*)\}/);return e&&e[1]?e[1].trim():t}async function ft(){try{let t=se.value;if(C.value&&T.value.name){const w={name:T.value.name,description:T.value.description||"",inputSchema:{type:"object",properties:T.value.parameters.reduce((E,G)=>(G.name&&G.name.trim()&&(E[G.name.trim()]={type:G.type,description:G.description||""}),E),{}),required:T.value.parameters.filter(E=>E.required).map(E=>E.name.trim())}};t=t.filter(E=>E.name!==T.value.name).concat(w)}const e=Rt({config:f.config,mcpTools:t,tables:B.value}),s=T.value.parameters.length>0?`type ToolArgs = {
|
|
482
|
+
${T.value.parameters.filter(w=>w.name&&w.name.trim()).map(w=>{const E=w.required?"":"?",N={string:"string",number:"number",boolean:"boolean",array:"any[]",object:"Record<string, any>"}[w.type]||"any",te=w.description?` /** ${w.description} */`:"";return` ${w.name.trim()}${E}: ${N};${te}`}).join(`
|
|
483
|
+
`)}
|
|
484
|
+
};`:"type ToolArgs = Record<string, any>;",a=T.value.serverScript.trim()||Ee,i=et(a),v=et(Ee),m=a!==Ee&&i!==v,d=T.value.name||"未命名工具",J=T.value.description||"无描述",x=vs({contextTypeDef:e,toolArgsType:s,functionBody:i,hasCustomImplementation:m,toolName:d,toolDescription:J,functionParams:"both"});await navigator.clipboard.writeText(x),g.success("提示词已复制到剪贴板!")}catch(t){console.error("Failed to copy prompt:",t),g.error("复制失败,请手动复制")}}function tt(){C.value=null,L.value="schema",U.value=!1,Q.value=!1,H.value="{}",P.value=null,R.value=!1;const t=M(null);T.value={name:"",description:"",serverScript:t||Ee,parameters:[]},I.value=""}me(()=>q.value,()=>{Te&&(Te.destroy(),Te=null),setTimeout(()=>{ve()},100)},{flush:"post"}),Tt(()=>{he(),Oe(),setTimeout(()=>{ve()},300)}),_t(()=>{Te&&(Te.destroy(),Te=null)});function ot(t,e){let s=null;return(...a)=>{s&&clearTimeout(s),s=setTimeout(()=>{t(...a)},e)}}const r=ot(he,300);return me(()=>f.config.components,()=>{r()},{deep:!0}),me(()=>L.value,t=>{t==="implementation"&&Me(()=>{be.value++})}),me(()=>T.value.parameters,()=>{Me(()=>{be.value++})},{deep:!0,immediate:!1}),me(()=>[T.value.name,T.value.description],()=>{Me(()=>{be.value++})},{immediate:!1}),me(()=>Q.value,t=>{var e;if(t){const s=((e=C.value)==null?void 0:e.id)||null,a=ge(s);a?H.value=a:H.value=qe()}}),me(()=>f.config.customTools,()=>{r()},{deep:!0}),me(()=>y.value,t=>{if(t){if(!C.value){const e=M(null);e&&(T.value.serverScript=e)}}else tt()}),(t,e)=>(A(),V("div",fs,[o("div",ys,[c(u(K),{type:"primary",size:"large",class:"add-tool-btn",onClick:e[0]||(e[0]=s=>y.value=!0)},{icon:l(()=>[...e[13]||(e[13]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M12 4v16m8-8H4",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:l(()=>[e[14]||(e[14]=F(" 添加工具 ",-1))]),_:1}),c(u(fe),{value:S.value,"onUpdate:value":e[1]||(e[1]=s=>S.value=s),placeholder:"搜索工具名称或描述...",size:"large",clearable:"",class:"search-input"},{prefix:l(()=>[...e[15]||(e[15]=[o("svg",{class:"search-icon",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),_:1},8,["value"])]),o("div",hs,[c(u(bt),{columns:n,data:q.value,pagination:_e,"row-props":ye,"row-key":s=>s.id,class:Se(["modern-table",{"draggable-table":!0}])},null,8,["data","row-key"])]),c(u(rt),{show:y.value,"onUpdate:show":e[9]||(e[9]=s=>y.value=s),preset:"card",bordered:!1,class:"tool-edit-modal",style:{width:"90vw",maxWidth:"1400px",height:"90vh",maxHeight:"90vh"}},{header:l(()=>[o("div",ws,[e[16]||(e[16]=o("div",{class:"modal-icon"},[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M14.7 6.3a1 1 0 000 1.4l1.6 1.6a1 1 0 001.4 0l3.77-3.77a6 6 0 01-7.94 7.94l-6.91 6.91a2.12 2.12 0 01-3-3l6.91-6.91a6 6 0 017.94-7.94l-3.76 3.76z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})])],-1)),o("div",null,[o("h3",bs,ee(C.value?"编辑自定义工具":"创建自定义工具"),1),o("p",ks,ee(C.value?"修改工具的 Schema 和实现代码":"定义工具的 Schema 并编写实现逻辑"),1)])])]),footer:l(()=>[o("div",Us,[c(u(K),{size:"large",onClick:e[8]||(e[8]=s=>y.value=!1)},{default:l(()=>[...e[36]||(e[36]=[F("取消",-1)])]),_:1}),c(u(K),{type:"primary",size:"large",loading:_.value,onClick:Je},{default:l(()=>[F(ee(C.value?"保存修改":"创建工具"),1)]),_:1},8,["loading"])])]),default:l(()=>[o("div",xs,[c(u(Ut),{ref_key:"formRef",ref:z,model:T.value,rules:dt,class:"tool-form"},{default:l(()=>[c(u(Ft),{value:L.value,"onUpdate:value":e[7]||(e[7]=s=>L.value=s),type:"line",animated:"",size:"large",class:"tool-config-tabs"},{default:l(()=>[c(u(lt),{name:"schema",tab:"Schema 声明"},{default:l(()=>[o("div",Cs,[c(u(Re),{type:"info",bordered:!1,class:"schema-tip"},{icon:l(()=>[...e[17]||(e[17]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:l(()=>[e[18]||(e[18]=F(' 在 Schema 声明中定义的参数会自动生成类型定义,在"工具实现"标签页的脚本编辑器中可以使用类型提示 ',-1))]),_:1}),o("div",Ts,[e[21]||(e[21]=o("h4",{class:"section-title"},"基础信息",-1)),o("div",$s,[c(u(de),{path:"name"},{label:l(()=>[...e[19]||(e[19]=[o("div",{class:"form-label"},[o("svg",{class:"label-icon",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})]),o("span",null,"工具名称")],-1)])]),default:l(()=>[c(u(fe),{value:T.value.name,"onUpdate:value":e[2]||(e[2]=s=>T.value.name=s),placeholder:"例如: my-custom-tool",size:"large"},null,8,["value"])]),_:1}),c(u(de),{path:"description"},{label:l(()=>[...e[20]||(e[20]=[o("div",{class:"form-label"},[o("svg",{class:"label-icon",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})]),o("span",null,"工具描述")],-1)])]),default:l(()=>[c(u(fe),{value:T.value.description,"onUpdate:value":e[3]||(e[3]=s=>T.value.description=s),placeholder:"简要描述工具的功能",size:"large"},null,8,["value"])]),_:1})])]),o("div",Ss,[o("div",Ps,[e[24]||(e[24]=o("h4",{class:"section-title"},"参数定义",-1)),c(u(K),{dashed:"",onClick:e[4]||(e[4]=s=>T.value.parameters.push(Ze())),size:"medium"},{icon:l(()=>[...e[22]||(e[22]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M12 4v16m8-8H4",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:l(()=>[e[23]||(e[23]=F(" 添加参数 ",-1))]),_:1})]),o("div",Ns,[(A(!0),V(nt,null,at(T.value.parameters,(s,a)=>(A(),V("div",{key:a,class:"parameter-card"},[o("div",js,[o("span",Ms,"#"+ee(a+1),1),c(u(K),{type:"error",text:"",size:"small",onClick:i=>T.value.parameters.splice(a,1)},{icon:l(()=>[...e[25]||(e[25]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:l(()=>[e[26]||(e[26]=F(" 删除 ",-1))]),_:1},8,["onClick"])]),o("div",Os,[c(u(de),{label:"必填",class:"required-field"},{default:l(()=>[c(u(Et),{checked:s.required,"onUpdate:checked":i=>s.required=i},null,8,["checked","onUpdate:checked"])]),_:2},1024),c(u(de),{label:"参数名",path:`parameters[${a}].name`,rule:{required:!0,message:"必填",trigger:"blur"}},{default:l(()=>[c(u(fe),{value:s.name,"onUpdate:value":i=>s.name=i,placeholder:"参数名"},null,8,["value","onUpdate:value"])]),_:2},1032,["path"]),c(u(de),{label:"类型"},{default:l(()=>[c(u(It),{value:s.type,"onUpdate:value":i=>s.type=i,options:ct},null,8,["value","onUpdate:value"])]),_:2},1024),c(u(de),{label:"描述"},{default:l(()=>[c(u(fe),{value:s.description,"onUpdate:value":i=>s.description=i,placeholder:"参数描述"},null,8,["value","onUpdate:value"])]),_:2},1024)])]))),128)),T.value.parameters.length===0?(A(),V("div",As,[...e[27]||(e[27]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"2"}),o("path",{d:"M12 16v-4m0-4h.01",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round"})],-1),o("p",null,"暂无参数,点击上方按钮添加参数",-1)])])):ae("",!0)])])])]),_:1}),c(u(lt),{name:"implementation",tab:"工具实现"},{default:l(()=>[o("div",Ds,[o("div",{class:Se(["editor-container",{fullscreen:U.value}])},[o("div",zs,[o("div",{class:Se(["status-dot",{unsaved:b.value,saved:!b.value}]),title:b.value?"未保存":"已保存"},null,10,_s)]),c(u(K),{type:"default",size:"small",class:"fullscreen-btn",onClick:vt},{icon:l(()=>[U.value?(A(),V("svg",Js,[...e[29]||(e[29]=[o("path",{d:"M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 1 2-2h3M3 16h3a2 2 0 0 1 2 2v3",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])])):(A(),V("svg",Bs,[...e[28]||(e[28]=[o("path",{d:"M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])]))]),default:l(()=>[F(" "+ee(U.value?"退出全屏":"全屏"),1)]),_:1}),o("div",Fs,[c(it,{modelValue:T.value.serverScript,"onUpdate:modelValue":e[5]||(e[5]=s=>T.value.serverScript=s),language:"typescript",options:{minimap:{enabled:!0},fontSize:14,lineHeight:22,padding:{top:16,bottom:16},scrollBeyondLastLine:!1,automaticLayout:!0},"extra-libs":Ae.value,onSave:Fe,onChange:We,style:xt(D.value)},null,8,["modelValue","extra-libs","style"])])],2),o("div",{class:Se(["editor-actions",{"fullscreen-actions":U.value}])},[c(u(K),{type:"default",size:"small",class:"copy-prompt-btn",onClick:ft},{icon:l(()=>[...e[30]||(e[30]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M8 5.00069C7.01165 5.00069 6.49359 5.00069 6.09202 5.21967C5.71569 5.42393 5.42413 5.71549 5.21987 6.09182C5 6.49339 5 7.01145 5 7.99979V15.9998C5 16.9881 5 17.5062 5.21987 17.9078C5.42413 18.2841 5.71569 18.5757 6.09202 18.7799C6.49359 18.9998 7.01165 18.9998 8 18.9998H16C16.9883 18.9998 17.5064 18.9998 17.908 18.7799C18.2843 18.5757 18.5759 18.2841 18.7801 17.9078C19 17.5062 19 16.9881 19 15.9998V7.99979C19 7.01145 19 6.49339 18.7801 6.09182C18.5759 5.71549 18.2843 5.42393 17.908 5.21967C17.5064 5.00069 16.9883 5.00069 16 5.00069H8Z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"}),o("path",{d:"M9 3.00069C9 2.4484 9 2.17226 9.08579 1.94418C9.18885 1.67761 9.37764 1.38893 9.58579 1.18378C9.79094 0.975636 10.0796 0.786849 10.3462 0.683785C10.5743 0.598 10.8504 0.598 11.4027 0.598H14.5973C15.1496 0.598 15.4257 0.598 15.6538 0.683785C15.9204 0.786849 16.2091 0.975636 16.4142 1.18378C16.6224 1.38893 16.8111 1.67761 16.9142 1.94418C17 2.17226 17 2.4484 17 3.00069V4.00069C17 4.55297 16.5523 5.00069 16 5.00069H8C7.44772 5.00069 7 4.55297 7 4.00069V3.00069C7 2.4484 7 2.17226 7.08579 1.94418C7.18885 1.67761 7.37764 1.38893 7.58579 1.18378C7.79094 0.975636 8.07963 0.786849 8.34621 0.683785C8.57428 0.598 8.85043 0.598 9.40272 0.598H12.5973C13.1496 0.598 13.4257 0.598 13.6538 0.683785C13.9204 0.786849 14.2091 0.975636 14.4142 1.18378C14.6224 1.38893 14.8111 1.67761 14.9142 1.94418C15 2.17226 15 2.4484 15 3.00069",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:l(()=>[e[31]||(e[31]=F(" 复制提示词到大模型生成 ",-1))]),_:1}),c(u(K),{type:"primary",size:"small",class:"save-btn",disabled:!b.value,onClick:Fe},{icon:l(()=>[...e[32]||(e[32]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M5 13l4 4L19 7",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:l(()=>[e[33]||(e[33]=F(" 保存 (Ctrl+S) ",-1))]),_:1},8,["disabled"]),c(u(K),{type:"info",size:"small",class:"test-btn",loading:j.value,onClick:e[6]||(e[6]=s=>Q.value=!0)},{icon:l(()=>[...e[34]||(e[34]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("polygon",{points:"5 3 19 12 5 21 5 3",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:l(()=>[e[35]||(e[35]=F(" 测试执行 ",-1))]),_:1},8,["loading"])],2)])]),_:1})]),_:1},8,["value"])]),_:1},8,["model"])])]),_:1},8,["show"]),c(u(rt),{show:Q.value,"onUpdate:show":e[12]||(e[12]=s=>Q.value=s),preset:"card",bordered:!1,class:"test-args-modal",style:xt({width:R.value?"800px":"600px"}),title:"测试执行参数"},{header:l(()=>[...e[37]||(e[37]=[o("div",{class:"modal-header"},[o("div",{class:"modal-icon"},[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("polygon",{points:"5 3 19 12 5 21 5 3",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})])]),o("div",null,[o("h3",{class:"modal-title"},"输入测试参数"),o("p",{class:"modal-subtitle"},'请输入 JSON 格式的参数(例如:{"param1": "value1", "param2": 123})')])],-1)])]),footer:l(()=>[o("div",sn,[c(u(K),{size:"large",onClick:Xe},{default:l(()=>[...e[48]||(e[48]=[F("取消",-1)])]),_:1}),c(u(K),{type:"primary",size:"large",loading:j.value,onClick:Qe},{default:l(()=>[...e[49]||(e[49]=[F(" 执行测试 ",-1)])]),_:1},8,["loading"])])]),default:l(()=>[o("div",Is,[T.value.parameters&&T.value.parameters.length>0?(A(),V("div",Es,[o("div",Vs,[e[38]||(e[38]=o("span",{class:"parameters-title"},"参数定义",-1)),o("span",Rs,ee(T.value.parameters.length)+" 个参数",1)]),c(u(bt),{columns:xe,data:T.value.parameters.filter(s=>s.name&&s.name.trim()),pagination:!1,size:"small",bordered:"",class:"test-args-table"},null,8,["data"])])):ae("",!0),o("div",Ls,[o("div",qs,[e[41]||(e[41]=o("span",{class:"test-args-input-title"},"测试参数 (JSON)",-1)),c(u(K),{size:"small",type:"default",onClick:Ye},{icon:l(()=>[(A(),V("svg",Hs,[...e[39]||(e[39]=[o("path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1),o("path",{d:"M21 3v5h-5",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1),o("path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1),o("path",{d:"M3 21v-5h5",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])]))]),default:l(()=>[e[40]||(e[40]=F(" 重置 ",-1))]),_:1})]),c(u(fe),{value:H.value,"onUpdate:value":e[10]||(e[10]=s=>H.value=s),type:"textarea",placeholder:'{"param1": "value1", "param2": 123}',rows:8,autosize:{minRows:8,maxRows:12},class:"test-args-input"},null,8,["value"])]),R.value&&P.value?(A(),V("div",Ks,[o("div",Gs,[o("div",Zs,[(A(),V("svg",Ws,[...e[42]||(e[42]=[o("path",{d:"M9 11l3 3L22 4",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1),o("path",{d:"M21 12v7a2 2 0 01-2 2H5a2 2 0 01-2-2V5a2 2 0 012-2h11",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])])),e[43]||(e[43]=o("span",null,"测试结果",-1))]),o("div",Qs,[c(u(K),{size:"small",text:"",onClick:Ie},{icon:l(()=>[(A(),V("svg",Ys,[...e[44]||(e[44]=[o("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1),o("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])]))]),default:l(()=>[e[45]||(e[45]=F(" 复制 ",-1))]),_:1}),c(u(K),{size:"small",text:"",onClick:e[11]||(e[11]=s=>R.value=!1)},{icon:l(()=>[(A(),V("svg",Xs,[...e[46]||(e[46]=[o("path",{d:"M18 6L6 18M6 6l12 12",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])]))]),_:1})])]),o("div",en,[o("pre",tn,[o("code",on,ee(Ue(P.value)),1),e[47]||(e[47]=F(`
|
|
485
|
+
`,-1))])])])):ae("",!0)])]),_:1},8,["show","style"])]))}}),xn=St(nn,[["__scopeId","data-v-e301d878"]]),an={class:"init-script-editor"},rn={class:"save-status-indicator"},ln=["title"],un={key:0,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},cn={key:1,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},dn={class:"monaco-wrapper"},pn={class:"editor-actions"},Ve=`/**
|
|
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",mn=ut({__name:"InitScriptEditor",props:{config:{}},emits:["update"],setup(p,{emit:O}){const f=$t(),h=p,g=O,y=$([]),_=$([]);async function C(){try{const n=await re.get("/configs/all-tools");n.data.success&&n.data.data.tools?y.value=n.data.data.tools:y.value=[]}catch(n){console.error("Failed to load MCP tools from database:",n),y.value=[]}}async function z(){try{const n=await re.get("/tables/definitions");n.data.success&&(_.value=n.data.data||[])}catch(n){console.error("Failed to load tables:",n),_.value=[]}}const S=ke(()=>Vt({config:h.config,mcpTools:y.value,tables:_.value})),L=ke(()=>[{content:S.value,filePath:"file:///init-script-context.d.ts"}]);Tt(()=>{C(),z()}),me(()=>h.config.components,()=>{C()},{deep:!0}),me(()=>h.config.customTools,()=>{C()},{deep:!0});function U(){try{return localStorage.getItem(kt)||null}catch(n){return console.error("Failed to load local script:",n),null}}function j(n){try{localStorage.setItem(kt,n)}catch(q){console.error("Failed to save to local storage:",q)}}function I(){try{localStorage.removeItem(kt)}catch(n){console.error("Failed to clear local script:",n)}}const Q=U(),H=h.config.initScript||"",R=$(Q||H||Ve),b=$(H),D=$(Q||""),se=ke(()=>R.value!==D.value),B=ke(()=>D.value!==b.value),W=$(!1),M=$(!1),ue=ke(()=>M.value?"height: 100%; border-radius: 12px; overflow: hidden;":"height: calc(100vh - 300px); min-height: 600px; max-height: 800px; border-radius: 12px; overflow: hidden;");me(()=>h.config.initScript,(n,q)=>{const X=n||"";if(X===(q||""))return;const he=U();if(he&&X===he){I(),D.value="",b.value=X,R.value=X;return}if(he&&X!==he){I(),D.value="",b.value=X;const Ne=X||Ve;R.value=Ne;return}if(b.value=X,!X&&b.value)return;const Oe=X||Ve;R.value=Oe,b.value=X},{immediate:!0});function Ce(n){}function ce(){const n=R.value.trim()||"";j(n),D.value=n,f.success("已保存到本地 (Ctrl+S)")}async function ge(){const n=D.value.trim()||void 0;g("update",{initScript:n}),b.value=n||"",I(),D.value=""}async function le(){var n,q;if(!R.value.trim()){f.warning("请先编写脚本内容");return}ce(),W.value=!0;try{const X=await re.post("/configs/test-init-script",{script:R.value});X.data.success?f.success("测试执行成功,请查看服务端控制台输出"):f.error(`测试执行失败: ${X.data.error}`)}catch(X){f.error(`测试执行失败: ${((q=(n=X.response)==null?void 0:n.data)==null?void 0:q.error)||X.message}`)}finally{W.value=!1}}function _e(){M.value=!M.value}function ye(n){const q=n.match(/export\s+default\s+async\s+function\s*\([^)]*\)\s*\{([\s\S]*)\}/);return q&&q[1]?q[1].trim():n}async function xe(){try{const n=Rt({config:h.config,mcpTools:y.value,tables:_.value}),q=y.value.map(be=>`- ${be.name}: ${be.description||"无描述"}`).join(`
|
|
500
|
+
`),X=_.value.map(be=>{const Ae=be.columns.map(T=>` - ${T.name} (${T.type}${T.nullable?", nullable":""})`).join(`
|
|
501
|
+
`);return`- ${be.name}: ${be.description||"无描述"}
|
|
502
|
+
${Ae}`}).join(`
|
|
503
|
+
|
|
504
|
+
`),we=R.value.trim()||Ve,he=ye(we),Oe=ye(Ve),Be=we!==Ve&&he!==Oe?`请帮我调整/优化以下函数的实现。
|
|
505
|
+
|
|
506
|
+
## 需求描述
|
|
507
|
+
|
|
508
|
+
[请在此处补充你的具体需求描述,说明需要如何调整或优化当前实现]
|
|
509
|
+
|
|
510
|
+
## 类型定义
|
|
511
|
+
|
|
512
|
+
\`\`\`typescript
|
|
513
|
+
${n}
|
|
514
|
+
\`\`\`
|
|
515
|
+
|
|
516
|
+
## 可用工具
|
|
517
|
+
|
|
518
|
+
${q||"暂无可用工具"}
|
|
519
|
+
|
|
520
|
+
## 可用数据表
|
|
521
|
+
|
|
522
|
+
${X||"暂无可用数据表"}
|
|
523
|
+
|
|
524
|
+
## 当前实现
|
|
525
|
+
|
|
526
|
+
\`\`\`typescript
|
|
527
|
+
export default async function(context: Context) {
|
|
528
|
+
${he}
|
|
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
|
+
${q||"暂无可用工具"}
|
|
561
|
+
|
|
562
|
+
## 可用数据表
|
|
563
|
+
|
|
564
|
+
${X||"暂无可用数据表"}
|
|
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(Be),f.success("提示词已复制到剪贴板!")}catch(n){console.error("Failed to copy prompt:",n),f.error("复制失败,请手动复制")}}return(n,q)=>(A(),V("div",an,[q[9]||(q[9]=Bt('<div class="editor-toolbar" data-v-515e2056><div class="toolbar-info" data-v-515e2056><svg class="info-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" data-v-515e2056><polyline points="16 18 22 12 16 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" data-v-515e2056></polyline><polyline points="8 6 2 12 8 18" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" data-v-515e2056></polyline></svg><span data-v-515e2056>初始化脚本在 MCP 连接时执行,用于初始化环境、加载数据等操作</span></div></div>',1)),o("div",{class:Se(["editor-container",{fullscreen:M.value}])},[o("div",rn,[o("div",{class:Se(["status-dot",{unsaved:se.value,saved:!se.value,"local-only":B.value&&!se.value}]),title:se.value?"未保存到本地":B.value?"已保存到本地,未上传":"已保存"},null,10,ln)]),c(u(K),{type:"default",size:"small",class:"fullscreen-btn",onClick:_e},{icon:l(()=>[M.value?(A(),V("svg",cn,[...q[2]||(q[2]=[o("path",{d:"M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 1 2-2h3M3 16h3a2 2 0 0 1 2 2v3",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])])):(A(),V("svg",un,[...q[1]||(q[1]=[o("path",{d:"M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)])]))]),default:l(()=>[F(" "+ee(M.value?"退出全屏":"全屏"),1)]),_:1}),o("div",dn,[c(it,{modelValue:R.value,"onUpdate:modelValue":q[0]||(q[0]=X=>R.value=X),language:"typescript",options:{minimap:{enabled:!0},fontSize:14,lineHeight:22,padding:{top:16,bottom:16},scrollBeyondLastLine:!1,automaticLayout:!0},"extra-libs":L.value,onSave:ce,onChange:Ce,style:xt(ue.value)},null,8,["modelValue","extra-libs","style"])]),o("div",pn,[c(u(K),{type:"default",size:"small",class:"copy-prompt-btn",onClick:xe},{icon:l(()=>[...q[3]||(q[3]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M8 5.00069C7.01165 5.00069 6.49359 5.00069 6.09202 5.21967C5.71569 5.42393 5.42413 5.71549 5.21987 6.09182C5 6.49339 5 7.01145 5 7.99979V15.9998C5 16.9881 5 17.5062 5.21987 17.9078C5.42413 18.2841 5.71569 18.5757 6.09202 18.7799C6.49359 18.9998 7.01165 18.9998 8 18.9998H16C16.9883 18.9998 17.5064 18.9998 17.908 18.7799C18.2843 18.5757 18.5759 18.2841 18.7801 17.9078C19 17.5062 19 16.9881 19 15.9998V7.99979C19 7.01145 19 6.49339 18.7801 6.09182C18.5759 5.71549 18.2843 5.42393 17.908 5.21967C17.5064 5.00069 16.9883 5.00069 16 5.00069H8Z",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"}),o("path",{d:"M9 3.00069C9 2.4484 9 2.17226 9.08579 1.94418C9.18885 1.67761 9.37764 1.38893 9.58579 1.18378C9.79094 0.975636 10.0796 0.786849 10.3462 0.683785C10.5743 0.598 10.8504 0.598 11.4027 0.598H14.5973C15.1496 0.598 15.4257 0.598 15.6538 0.683785C15.9204 0.786849 16.2091 0.975636 16.4142 1.18378C16.6224 1.38893 16.8111 1.67761 16.9142 1.94418C17 2.17226 17 2.4484 17 3.00069V4.00069C17 4.55297 16.5523 5.00069 16 5.00069H8C7.44772 5.00069 7 4.55297 7 4.00069V3.00069C7 2.4484 7 2.17226 7.08579 1.94418C7.18885 1.67761 7.37764 1.38893 7.58579 1.18378C7.79094 0.975636 8.07963 0.786849 8.34621 0.683785C8.57428 0.598 8.85043 0.598 9.40272 0.598H12.5973C13.1496 0.598 13.4257 0.598 13.6538 0.683785C13.9204 0.786849 14.2091 0.975636 14.4142 1.18378C14.6224 1.38893 14.8111 1.67761 14.9142 1.94418C15 2.17226 15 2.4484 15 3.00069",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:l(()=>[q[4]||(q[4]=F(" 复制提示词到大模型生成 ",-1))]),_:1}),c(u(K),{type:"primary",size:"small",class:"upload-btn",disabled:!B.value,onClick:ge},{icon:l(()=>[...q[5]||(q[5]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"}),o("polyline",{points:"17 8 12 3 7 8",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"}),o("line",{x1:"12",y1:"3",x2:"12",y2:"15",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:l(()=>[q[6]||(q[6]=F(" 上传脚本 ",-1))]),_:1},8,["disabled"]),c(u(K),{type:"info",size:"small",class:"test-btn",loading:W.value,onClick:le},{icon:l(()=>[...q[7]||(q[7]=[o("svg",{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[o("polygon",{points:"5 3 19 12 5 21 5 3",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),default:l(()=>[q[8]||(q[8]=F(" 测试执行 ",-1))]),_:1},8,["loading"])])],2)]))}}),Cn=St(mn,[["__scopeId","data-v-515e2056"]]);export{xn as C,Cn as I,kn as M,it as _,Vt as a,Ke as g,bn as p,wn as u};
|