vite-plugin-aipanel 1.2.0-beta.0
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/README.md +72 -0
- package/es/client/vue-devtools-bridge.d.ts +58 -0
- package/es/client/vue-devtools-bridge.mjs +150 -0
- package/es/core/injector.d.ts +2 -0
- package/es/core/injector.mjs +15 -0
- package/es/core/mcp-chrome.d.ts +56 -0
- package/es/core/mcp-chrome.mjs +133 -0
- package/es/core/mcp-proxy.d.ts +23 -0
- package/es/core/mcp-proxy.mjs +212 -0
- package/es/core/mcp-tools.d.ts +15 -0
- package/es/core/mcp-tools.mjs +671 -0
- package/es/core/provider-loader.d.ts +19 -0
- package/es/core/provider-loader.mjs +30 -0
- package/es/core/proxy-server.d.ts +12 -0
- package/es/core/proxy-server.mjs +148 -0
- package/es/core/service.d.ts +39 -0
- package/es/core/service.mjs +267 -0
- package/es/endpoints/context.d.ts +3 -0
- package/es/endpoints/context.mjs +106 -0
- package/es/endpoints/index.d.ts +9 -0
- package/es/endpoints/index.mjs +30 -0
- package/es/endpoints/logs.d.ts +9 -0
- package/es/endpoints/logs.mjs +86 -0
- package/es/endpoints/mcp.d.ts +6 -0
- package/es/endpoints/mcp.mjs +610 -0
- package/es/endpoints/sessions.d.ts +3 -0
- package/es/endpoints/sessions.mjs +62 -0
- package/es/endpoints/sse.d.ts +3 -0
- package/es/endpoints/sse.mjs +44 -0
- package/es/endpoints/start.d.ts +3 -0
- package/es/endpoints/start.mjs +21 -0
- package/es/endpoints/types.d.ts +34 -0
- package/es/endpoints/types.mjs +0 -0
- package/es/endpoints/vue-devtools.d.ts +9 -0
- package/es/endpoints/vue-devtools.mjs +107 -0
- package/es/endpoints/warmup.d.ts +3 -0
- package/es/endpoints/warmup.mjs +42 -0
- package/es/endpoints/widget.d.ts +3 -0
- package/es/endpoints/widget.mjs +36 -0
- package/es/env.d.ts +1 -0
- package/es/index.d.ts +22 -0
- package/es/index.mjs +342 -0
- package/es/utils/format-bridge.d.ts +9 -0
- package/es/utils/format-bridge.mjs +80 -0
- package/es/utils/paths.d.ts +3 -0
- package/es/utils/paths.mjs +45 -0
- package/es/utils/system.d.ts +3 -0
- package/es/utils/system.mjs +76 -0
- package/lib/client/vue-devtools-bridge.cjs +150 -0
- package/lib/client/vue-devtools-bridge.d.ts +58 -0
- package/lib/client.css +2 -0
- package/lib/client.js +6950 -0
- package/lib/core/injector.cjs +34 -0
- package/lib/core/injector.d.ts +2 -0
- package/lib/core/mcp-chrome.cjs +161 -0
- package/lib/core/mcp-chrome.d.ts +56 -0
- package/lib/core/mcp-proxy.cjs +244 -0
- package/lib/core/mcp-proxy.d.ts +23 -0
- package/lib/core/mcp-tools.cjs +694 -0
- package/lib/core/mcp-tools.d.ts +15 -0
- package/lib/core/provider-loader.cjs +53 -0
- package/lib/core/provider-loader.d.ts +19 -0
- package/lib/core/proxy-server.cjs +181 -0
- package/lib/core/proxy-server.d.ts +12 -0
- package/lib/core/service.cjs +289 -0
- package/lib/core/service.d.ts +39 -0
- package/lib/endpoints/context.cjs +129 -0
- package/lib/endpoints/context.d.ts +3 -0
- package/lib/endpoints/index.cjs +58 -0
- package/lib/endpoints/index.d.ts +9 -0
- package/lib/endpoints/logs.cjs +107 -0
- package/lib/endpoints/logs.d.ts +9 -0
- package/lib/endpoints/mcp.cjs +624 -0
- package/lib/endpoints/mcp.d.ts +6 -0
- package/lib/endpoints/sessions.cjs +85 -0
- package/lib/endpoints/sessions.d.ts +3 -0
- package/lib/endpoints/sse.cjs +67 -0
- package/lib/endpoints/sse.d.ts +3 -0
- package/lib/endpoints/start.cjs +44 -0
- package/lib/endpoints/start.d.ts +3 -0
- package/lib/endpoints/types.cjs +15 -0
- package/lib/endpoints/types.d.ts +34 -0
- package/lib/endpoints/vue-devtools.cjs +132 -0
- package/lib/endpoints/vue-devtools.d.ts +9 -0
- package/lib/endpoints/warmup.cjs +65 -0
- package/lib/endpoints/warmup.d.ts +3 -0
- package/lib/endpoints/widget.cjs +69 -0
- package/lib/endpoints/widget.d.ts +3 -0
- package/lib/env.d.ts +1 -0
- package/lib/index.cjs +361 -0
- package/lib/index.d.ts +22 -0
- package/lib/utils/format-bridge.cjs +102 -0
- package/lib/utils/format-bridge.d.ts +9 -0
- package/lib/utils/paths.cjs +80 -0
- package/lib/utils/paths.d.ts +3 -0
- package/lib/utils/system.cjs +110 -0
- package/lib/utils/system.d.ts +3 -0
- package/package.json +68 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __typeError = (msg) => {
|
|
3
|
+
throw TypeError(msg);
|
|
4
|
+
};
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
8
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
9
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
10
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
11
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
12
|
+
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
13
|
+
set _(value) {
|
|
14
|
+
__privateSet(obj, member, value, setter);
|
|
15
|
+
},
|
|
16
|
+
get _() {
|
|
17
|
+
return __privateGet(obj, member, getter);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
var _proc, _rl, _messageId, _internalIdBase, _pending, _args, _startPromise, _idleTimer, _idleTimeout, _McpProxy_instances, doStart_fn, resetIdleTimer_fn;
|
|
21
|
+
import { spawn } from "node:child_process";
|
|
22
|
+
import { createInterface } from "node:readline";
|
|
23
|
+
import crypto from "node:crypto";
|
|
24
|
+
import path from "node:path";
|
|
25
|
+
import { createLogger, createPackageRequire, resolvePackageDir } from "@aipanel/core/node";
|
|
26
|
+
const log = createLogger("McpProxy");
|
|
27
|
+
function resolveChromeDevToolsMcpBin() {
|
|
28
|
+
const pluginDir = resolvePackageDir("vite-plugin-aipanel");
|
|
29
|
+
const require2 = createPackageRequire(pluginDir);
|
|
30
|
+
const pkgJsonPath = require2.resolve("chrome-devtools-mcp/package.json");
|
|
31
|
+
const pkgDir = path.dirname(pkgJsonPath);
|
|
32
|
+
const { bin } = require2(pkgJsonPath);
|
|
33
|
+
const binEntry = typeof bin === "string" ? bin : Object.values(bin)[0];
|
|
34
|
+
return path.resolve(pkgDir, binEntry);
|
|
35
|
+
}
|
|
36
|
+
class McpProxy {
|
|
37
|
+
constructor(options = {}) {
|
|
38
|
+
__privateAdd(this, _McpProxy_instances);
|
|
39
|
+
__privateAdd(this, _proc, null);
|
|
40
|
+
__privateAdd(this, _rl, null);
|
|
41
|
+
__privateAdd(this, _messageId, 0);
|
|
42
|
+
/** 内部调用使用的高位 ID 起始值,避免与客户端 ID 冲突 */
|
|
43
|
+
__privateAdd(this, _internalIdBase, 1e6);
|
|
44
|
+
__privateAdd(this, _pending, /* @__PURE__ */ new Map());
|
|
45
|
+
__privateAdd(this, _args);
|
|
46
|
+
__privateAdd(this, _startPromise, null);
|
|
47
|
+
__privateAdd(this, _idleTimer, null);
|
|
48
|
+
__privateAdd(this, _idleTimeout);
|
|
49
|
+
__publicField(this, "sessionId");
|
|
50
|
+
__privateSet(this, _args, options.args ?? [
|
|
51
|
+
"--auto-connect",
|
|
52
|
+
"--no-usage-statistics",
|
|
53
|
+
"--no-performance-crux"
|
|
54
|
+
]);
|
|
55
|
+
__privateSet(this, _idleTimeout, options.idleTimeout ?? 0);
|
|
56
|
+
this.sessionId = crypto.randomUUID();
|
|
57
|
+
}
|
|
58
|
+
get isRunning() {
|
|
59
|
+
return __privateGet(this, _proc) !== null && !__privateGet(this, _proc).killed;
|
|
60
|
+
}
|
|
61
|
+
async start() {
|
|
62
|
+
if (this.isRunning) return;
|
|
63
|
+
if (__privateGet(this, _startPromise)) return __privateGet(this, _startPromise);
|
|
64
|
+
__privateSet(this, _startPromise, __privateMethod(this, _McpProxy_instances, doStart_fn).call(this));
|
|
65
|
+
return __privateGet(this, _startPromise);
|
|
66
|
+
}
|
|
67
|
+
/** 转发原始 JSON-RPC 请求,保留客户端 ID */
|
|
68
|
+
async forward(rawRequest) {
|
|
69
|
+
await this.start();
|
|
70
|
+
if (!__privateGet(this, _proc) || !__privateGet(this, _proc).stdin) {
|
|
71
|
+
throw new Error("MCP process not available");
|
|
72
|
+
}
|
|
73
|
+
__privateMethod(this, _McpProxy_instances, resetIdleTimer_fn).call(this);
|
|
74
|
+
let msg;
|
|
75
|
+
try {
|
|
76
|
+
msg = JSON.parse(rawRequest);
|
|
77
|
+
} catch {
|
|
78
|
+
throw new Error("Invalid JSON-RPC request");
|
|
79
|
+
}
|
|
80
|
+
return new Promise((resolve) => {
|
|
81
|
+
const id = msg.id;
|
|
82
|
+
if (id !== void 0) {
|
|
83
|
+
__privateGet(this, _pending).set(id, (raw) => resolve(JSON.stringify(raw)));
|
|
84
|
+
} else {
|
|
85
|
+
__privateGet(this, _proc).stdin.write(rawRequest + "\n");
|
|
86
|
+
resolve("");
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
__privateGet(this, _proc).stdin.write(rawRequest + "\n");
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/** 调用 MCP 工具 */
|
|
93
|
+
async call(method, params = {}) {
|
|
94
|
+
await this.start();
|
|
95
|
+
if (!__privateGet(this, _proc) || !__privateGet(this, _proc).stdin) {
|
|
96
|
+
throw new Error("MCP process not available");
|
|
97
|
+
}
|
|
98
|
+
__privateMethod(this, _McpProxy_instances, resetIdleTimer_fn).call(this);
|
|
99
|
+
const id = __privateGet(this, _internalIdBase) + ++__privateWrapper(this, _messageId)._;
|
|
100
|
+
return new Promise((resolve) => {
|
|
101
|
+
__privateGet(this, _pending).set(id, resolve);
|
|
102
|
+
const request = JSON.stringify({ jsonrpc: "2.0", id, method, params });
|
|
103
|
+
__privateGet(this, _proc).stdin.write(request + "\n");
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/** 直接调用 chrome-devtools-mcp 底层工具(内部使用) */
|
|
107
|
+
async callChromeDevTool(name, args = {}) {
|
|
108
|
+
return this.call("tools/call", { name, arguments: args });
|
|
109
|
+
}
|
|
110
|
+
/** 验证 MCP 是否可用 + 预热 CDP 连接 */
|
|
111
|
+
async verify() {
|
|
112
|
+
try {
|
|
113
|
+
await this.callChromeDevTool("list_pages", {});
|
|
114
|
+
return { ok: true };
|
|
115
|
+
} catch (e) {
|
|
116
|
+
return { ok: false, error: e instanceof Error ? e.message : String(e) };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
stop() {
|
|
120
|
+
if (__privateGet(this, _idleTimer)) clearTimeout(__privateGet(this, _idleTimer));
|
|
121
|
+
const err = new Error("MCP server shutting down");
|
|
122
|
+
for (const resolve of __privateGet(this, _pending).values()) {
|
|
123
|
+
resolve({ error: { code: -32e3, message: err.message } });
|
|
124
|
+
}
|
|
125
|
+
__privateGet(this, _pending).clear();
|
|
126
|
+
if (__privateGet(this, _rl)) {
|
|
127
|
+
__privateGet(this, _rl).close();
|
|
128
|
+
__privateSet(this, _rl, null);
|
|
129
|
+
}
|
|
130
|
+
if (__privateGet(this, _proc) && !__privateGet(this, _proc).killed) {
|
|
131
|
+
__privateGet(this, _proc).kill();
|
|
132
|
+
__privateSet(this, _proc, null);
|
|
133
|
+
}
|
|
134
|
+
__privateSet(this, _startPromise, null);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
_proc = new WeakMap();
|
|
138
|
+
_rl = new WeakMap();
|
|
139
|
+
_messageId = new WeakMap();
|
|
140
|
+
_internalIdBase = new WeakMap();
|
|
141
|
+
_pending = new WeakMap();
|
|
142
|
+
_args = new WeakMap();
|
|
143
|
+
_startPromise = new WeakMap();
|
|
144
|
+
_idleTimer = new WeakMap();
|
|
145
|
+
_idleTimeout = new WeakMap();
|
|
146
|
+
_McpProxy_instances = new WeakSet();
|
|
147
|
+
doStart_fn = async function() {
|
|
148
|
+
log.debug("Starting MCP process", { args: __privateGet(this, _args) });
|
|
149
|
+
try {
|
|
150
|
+
const binPath = resolveChromeDevToolsMcpBin();
|
|
151
|
+
__privateSet(this, _proc, spawn(process.execPath, [binPath, ...__privateGet(this, _args)], {
|
|
152
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
153
|
+
}));
|
|
154
|
+
log.debug("Using local chrome-devtools-mcp");
|
|
155
|
+
} catch {
|
|
156
|
+
throw new Error(
|
|
157
|
+
"Cannot find chrome-devtools-mcp. Please ensure it is installed: npm install chrome-devtools-mcp"
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
__privateSet(this, _rl, createInterface({ input: __privateGet(this, _proc).stdout }));
|
|
161
|
+
__privateGet(this, _rl).on("line", (line) => {
|
|
162
|
+
try {
|
|
163
|
+
const msg = JSON.parse(line);
|
|
164
|
+
log.debug("MCP stdout", {
|
|
165
|
+
id: msg.id,
|
|
166
|
+
method: msg.method,
|
|
167
|
+
hasResult: !!msg.result,
|
|
168
|
+
hasError: !!msg.error
|
|
169
|
+
});
|
|
170
|
+
if (msg.id !== void 0 && __privateGet(this, _pending).has(msg.id)) {
|
|
171
|
+
const resolve = __privateGet(this, _pending).get(msg.id);
|
|
172
|
+
__privateGet(this, _pending).delete(msg.id);
|
|
173
|
+
log.debug("MCP pending resolved", { id: msg.id });
|
|
174
|
+
resolve(msg);
|
|
175
|
+
}
|
|
176
|
+
} catch {
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
__privateGet(this, _proc).stderr?.on("data", (d) => {
|
|
180
|
+
const text = d.toString().trim();
|
|
181
|
+
if (!text || /No handler registered for issue code \w+/i.test(text)) return;
|
|
182
|
+
log.debug("[MCP stderr]", { text: text.substring(0, 200) });
|
|
183
|
+
});
|
|
184
|
+
__privateGet(this, _proc).on("close", (code) => {
|
|
185
|
+
log.debug("MCP process closed", { code });
|
|
186
|
+
for (const resolve of __privateGet(this, _pending).values()) {
|
|
187
|
+
resolve({ error: { code: -32e3, message: `MCP process exited with code ${code}` } });
|
|
188
|
+
}
|
|
189
|
+
__privateGet(this, _pending).clear();
|
|
190
|
+
__privateSet(this, _proc, null);
|
|
191
|
+
__privateSet(this, _rl, null);
|
|
192
|
+
__privateSet(this, _startPromise, null);
|
|
193
|
+
});
|
|
194
|
+
await this.call("initialize", {
|
|
195
|
+
protocolVersion: "2024-11-05",
|
|
196
|
+
capabilities: {},
|
|
197
|
+
clientInfo: { name: "vite-plugin-aipanel", version: "1.0.0" }
|
|
198
|
+
});
|
|
199
|
+
log.debug("MCP proxy ready");
|
|
200
|
+
__privateSet(this, _startPromise, null);
|
|
201
|
+
};
|
|
202
|
+
resetIdleTimer_fn = function() {
|
|
203
|
+
if (__privateGet(this, _idleTimeout) <= 0) return;
|
|
204
|
+
if (__privateGet(this, _idleTimer)) clearTimeout(__privateGet(this, _idleTimer));
|
|
205
|
+
__privateSet(this, _idleTimer, setTimeout(() => {
|
|
206
|
+
log.debug("MCP process idle timeout, stopping");
|
|
207
|
+
this.stop();
|
|
208
|
+
}, __privateGet(this, _idleTimeout)));
|
|
209
|
+
};
|
|
210
|
+
export {
|
|
211
|
+
McpProxy
|
|
212
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 自定义 DevTools 工具定义
|
|
3
|
+
* 所有工具(除 chrome-devtools_list_pages)必须传入 pageId 参数,
|
|
4
|
+
* 代理层校验 pageId 是否为项目页面后方可调用 chrome-devtools-mcp。
|
|
5
|
+
*/
|
|
6
|
+
export interface CustomTool {
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
inputSchema: {
|
|
10
|
+
type: "object";
|
|
11
|
+
properties: Record<string, unknown>;
|
|
12
|
+
required?: string[];
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export declare const CUSTOM_TOOLS: CustomTool[];
|