完成插件端
This commit is contained in:
parent
f3677ad60f
commit
256d5e7bf3
25
package-lock.json
generated
25
package-lock.json
generated
@ -12,7 +12,8 @@
|
|||||||
"axios": "^1.7.7",
|
"axios": "^1.7.7",
|
||||||
"bson": "^6.8.0",
|
"bson": "^6.8.0",
|
||||||
"openai": "^4.93.0",
|
"openai": "^4.93.0",
|
||||||
"pako": "^2.1.0"
|
"pako": "^2.1.0",
|
||||||
|
"ws": "^8.18.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "16.x",
|
"@types/node": "16.x",
|
||||||
@ -21,7 +22,7 @@
|
|||||||
"@types/vscode": "^1.72.0"
|
"@types/vscode": "^1.72.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"vscode": "^1.98.0"
|
"vscode": "^1.95.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@modelcontextprotocol/sdk": {
|
"node_modules/@modelcontextprotocol/sdk": {
|
||||||
@ -1398,6 +1399,26 @@
|
|||||||
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
|
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
|
||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
},
|
},
|
||||||
|
"node_modules/ws": {
|
||||||
|
"version": "8.18.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/ws/-/ws-8.18.1.tgz",
|
||||||
|
"integrity": "sha512-RKW2aJZMXeMxVpnZ6bck+RswznaxmzdULiBr6KY7XkTnW8uvt0iT9H5DkHUChXrc+uurzwa0rVI16n/Xzjdz1w==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10.0.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"bufferutil": "^4.0.1",
|
||||||
|
"utf-8-validate": ">=5.0.2"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"bufferutil": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"utf-8-validate": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/zod": {
|
"node_modules/zod": {
|
||||||
"version": "3.24.2",
|
"version": "3.24.2",
|
||||||
"resolved": "https://registry.npmjs.org/zod/-/zod-3.24.2.tgz",
|
"resolved": "https://registry.npmjs.org/zod/-/zod-3.24.2.tgz",
|
||||||
|
12
package.json
12
package.json
@ -4,7 +4,7 @@
|
|||||||
"description": "A MCP Client for MCP/OpenMCP",
|
"description": "A MCP Client for MCP/OpenMCP",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"engines": {
|
"engines": {
|
||||||
"vscode": "^1.98.0"
|
"vscode": "^1.95.0"
|
||||||
},
|
},
|
||||||
"categories": [
|
"categories": [
|
||||||
"Other"
|
"Other"
|
||||||
@ -12,6 +12,13 @@
|
|||||||
"activationEvents": [],
|
"activationEvents": [],
|
||||||
"main": "./dist/extension.js",
|
"main": "./dist/extension.js",
|
||||||
"contributes": {
|
"contributes": {
|
||||||
|
"commands": [
|
||||||
|
{
|
||||||
|
"command": "openmcp.showOpenMCP",
|
||||||
|
"title": "展示 OpenMCP",
|
||||||
|
"category": "openmcp"
|
||||||
|
}
|
||||||
|
],
|
||||||
"viewsContainers": {
|
"viewsContainers": {
|
||||||
"activitybar": [
|
"activitybar": [
|
||||||
{
|
{
|
||||||
@ -45,7 +52,8 @@
|
|||||||
"axios": "^1.7.7",
|
"axios": "^1.7.7",
|
||||||
"bson": "^6.8.0",
|
"bson": "^6.8.0",
|
||||||
"openai": "^4.93.0",
|
"openai": "^4.93.0",
|
||||||
"pako": "^2.1.0"
|
"pako": "^2.1.0",
|
||||||
|
"ws": "^8.18.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "16.x",
|
"@types/node": "16.x",
|
||||||
|
@ -9,25 +9,25 @@ const routes: Array<RouteRecordRaw> = [
|
|||||||
{
|
{
|
||||||
path: "/debug",
|
path: "/debug",
|
||||||
name: "debug",
|
name: "debug",
|
||||||
component: () => import("@/views/debug/index.vue"),
|
component: () => import( /* webpackMode: "eager" */ "@/views/debug/index.vue"),
|
||||||
meta: { title: "Debug" }
|
meta: { title: "Debug" }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/connect",
|
path: "/connect",
|
||||||
name: "connect",
|
name: "connect",
|
||||||
component: () => import("@/views/connect/index.vue"),
|
component: () => import( /* webpackMode: "eager" */ "@/views/connect/index.vue"),
|
||||||
meta: { title: "Connect" }
|
meta: { title: "Connect" }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/setting",
|
path: "/setting",
|
||||||
name: "setting",
|
name: "setting",
|
||||||
component: () => import("@/views/setting/index.vue"),
|
component: () => import( /* webpackMode: "eager" */ "@/views/setting/index.vue"),
|
||||||
meta: { title: "Setting" }
|
meta: { title: "Setting" }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/about",
|
path: "/about",
|
||||||
name: "about",
|
name: "about",
|
||||||
component: () => import("@/views/about/index.vue"),
|
component: () => import( /* webpackMode: "eager" */ "@/views/about/index.vue"),
|
||||||
meta: { title: "Tools" }
|
meta: { title: "Tools" }
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
@ -1,4 +1,21 @@
|
|||||||
const { defineConfig } = require("@vue/cli-service");
|
const { defineConfig } = require("@vue/cli-service");
|
||||||
module.exports = defineConfig({
|
module.exports = defineConfig({
|
||||||
transpileDependencies: true,
|
transpileDependencies: true,
|
||||||
|
publicPath: process.env.NODE_ENV === 'production' ? '' : '/',
|
||||||
|
configureWebpack: {
|
||||||
|
optimization: {
|
||||||
|
splitChunks: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
chainWebpack: config => {
|
||||||
|
// 删除所有预设的代码分割规则
|
||||||
|
config.optimization.delete('splitChunks');
|
||||||
|
|
||||||
|
// 确保路由组件同步加载
|
||||||
|
config.plugins.delete('prefetch');
|
||||||
|
config.plugins.delete('preload');
|
||||||
|
},
|
||||||
|
css: {
|
||||||
|
extract: false
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
@ -2,14 +2,15 @@ import * as vscode from 'vscode';
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as fspath from 'path';
|
import * as fspath from 'path';
|
||||||
|
|
||||||
import * as OpenMCPService from '@resources/service';
|
import * as OpenMCPService from '../resources/service';
|
||||||
|
|
||||||
function getWebviewContent(context: vscode.ExtensionContext, panel?: vscode.WebviewPanel): string | undefined {
|
function getWebviewContent(context: vscode.ExtensionContext, panel: vscode.WebviewPanel): string | undefined {
|
||||||
const viewRoot = fspath.join(context.extensionPath, 'resources', 'renderer');
|
const viewRoot = fspath.join(context.extensionPath, 'resources', 'renderer');
|
||||||
const htmlIndexPath = fspath.join(viewRoot, 'index.html');
|
const htmlIndexPath = fspath.join(viewRoot, 'index.html');
|
||||||
const html = fs.readFileSync(htmlIndexPath, { encoding: 'utf-8' })?.replace(/(<link.+?href="|<script.+?src="|<img.+?src=")(.+?)"/g, (m, $1, $2) => {
|
const html = fs.readFileSync(htmlIndexPath, { encoding: 'utf-8' })?.replace(/(<link.+?href="|<script.+?src="|<img.+?src=")(.+?)"/g, (m, $1, $2) => {
|
||||||
const absLocalPath = fspath.resolve(viewRoot, $2);
|
const absLocalPath = fspath.resolve(viewRoot, $2);
|
||||||
const webviewUri = panel?.webview.asWebviewUri(vscode.Uri.file(absLocalPath));
|
const webviewUri = panel.webview.asWebviewUri(vscode.Uri.file(absLocalPath));
|
||||||
|
|
||||||
const replaceHref = $1 + webviewUri?.toString() + '"';
|
const replaceHref = $1 + webviewUri?.toString() + '"';
|
||||||
return replaceHref;
|
return replaceHref;
|
||||||
});
|
});
|
||||||
@ -22,58 +23,39 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
// 注册 showOpenMCP 命令
|
// 注册 showOpenMCP 命令
|
||||||
context.subscriptions.push(
|
context.subscriptions.push(
|
||||||
vscode.commands.registerCommand('openmcp.showOpenMCP', async () => {
|
vscode.commands.registerCommand('openmcp.showOpenMCP', async () => {
|
||||||
|
|
||||||
const panel = vscode.window.createWebviewPanel(
|
const panel = vscode.window.createWebviewPanel(
|
||||||
'openmcpView',
|
'OpenMCP',
|
||||||
'OpenMCP',
|
'OpenMCP',
|
||||||
vscode.ViewColumn.One,
|
vscode.ViewColumn.One,
|
||||||
{
|
{
|
||||||
enableScripts: true,
|
enableScripts: true,
|
||||||
retainContextWhenHidden: true
|
retainContextWhenHidden: true,
|
||||||
|
enableFindWidget: true
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
initaliseWebview(context, panel.webview);
|
// 设置HTML内容
|
||||||
|
const html = getWebviewContent(context, panel);
|
||||||
|
panel.webview.html = html || '';
|
||||||
|
|
||||||
|
// 处理来自webview的消息
|
||||||
|
panel.webview.onDidReceiveMessage(message => {
|
||||||
|
const { command, data } = message;
|
||||||
|
console.log('receive message', message);
|
||||||
|
|
||||||
|
OpenMCPService.messageController(command, data, panel.webview as any);
|
||||||
|
});
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
const provider = new WebviewViewProvider(context);
|
// const provider = new WebviewViewProvider(context);
|
||||||
|
|
||||||
context.subscriptions.push(
|
// context.subscriptions.push(
|
||||||
vscode.window.registerWebviewViewProvider('webview-sidebar.view', provider)
|
// vscode.window.registerWebviewViewProvider('webview-sidebar.view', provider)
|
||||||
);
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
function initaliseWebview(context: vscode.ExtensionContext, webview: vscode.Webview) {
|
|
||||||
webview.options = {
|
|
||||||
enableScripts: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
// 设置HTML内容
|
|
||||||
const html = getWebviewContent(context);
|
|
||||||
webview.html = html || '';
|
|
||||||
|
|
||||||
// 处理来自webview的消息
|
|
||||||
webview.onDidReceiveMessage(message => {
|
|
||||||
const { command, data } = message;
|
|
||||||
|
|
||||||
OpenMCPService.messageController(command, data, webview as any);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
class WebviewViewProvider implements vscode.WebviewViewProvider {
|
|
||||||
private _view?: vscode.WebviewView;
|
|
||||||
|
|
||||||
constructor(private readonly context: vscode.ExtensionContext) {}
|
|
||||||
|
|
||||||
public resolveWebviewView(
|
|
||||||
webviewView: vscode.WebviewView,
|
|
||||||
_context: vscode.WebviewViewResolveContext,
|
|
||||||
_token: vscode.CancellationToken,
|
|
||||||
) {
|
|
||||||
this._view = webviewView;
|
|
||||||
initaliseWebview(this.context, webviewView.webview);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function deactivate() {
|
export function deactivate() {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user