vite-plugin-aipanel 1.2.8 → 1.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/es/core/chrome-project.d.ts +15 -0
  2. package/es/core/chrome-project.mjs +13 -0
  3. package/es/core/mcp-chrome.d.ts +12 -8
  4. package/es/core/mcp-chrome.mjs +52 -10
  5. package/es/core/mcp-proxy.d.ts +21 -1
  6. package/es/core/mcp-proxy.mjs +83 -12
  7. package/es/core/mcp-tools.d.ts +51 -3
  8. package/es/core/mcp-tools.mjs +109 -659
  9. package/es/core/official-meta.d.ts +9 -0
  10. package/es/core/official-meta.mjs +62 -0
  11. package/es/core/official-tools.d.ts +7 -0
  12. package/es/core/official-tools.mjs +54 -0
  13. package/es/core/proxy-server.mjs +16 -13
  14. package/es/core/service.mjs +4 -5
  15. package/es/endpoints/context.mjs +2 -2
  16. package/es/endpoints/host-events.mjs +1 -2
  17. package/es/endpoints/index.d.ts +2 -2
  18. package/es/endpoints/index.mjs +2 -2
  19. package/es/endpoints/mcp.d.ts +2 -2
  20. package/es/endpoints/mcp.mjs +116 -87
  21. package/es/endpoints/sse.mjs +3 -3
  22. package/es/endpoints/vue-devtools.d.ts +5 -2
  23. package/es/endpoints/vue-devtools.mjs +3 -4
  24. package/es/index.mjs +29 -6
  25. package/lib/client.js +2380 -2369
  26. package/lib/core/chrome-project.cjs +36 -0
  27. package/lib/core/chrome-project.d.ts +15 -0
  28. package/lib/core/mcp-chrome.cjs +64 -10
  29. package/lib/core/mcp-chrome.d.ts +12 -8
  30. package/lib/core/mcp-proxy.cjs +87 -13
  31. package/lib/core/mcp-proxy.d.ts +21 -1
  32. package/lib/core/mcp-tools.cjs +124 -660
  33. package/lib/core/mcp-tools.d.ts +51 -3
  34. package/lib/core/official-meta.cjs +85 -0
  35. package/lib/core/official-meta.d.ts +9 -0
  36. package/lib/core/official-tools.cjs +70 -0
  37. package/lib/core/official-tools.d.ts +7 -0
  38. package/lib/core/proxy-server.cjs +16 -13
  39. package/lib/core/service.cjs +4 -5
  40. package/lib/endpoints/context.cjs +1 -1
  41. package/lib/endpoints/host-events.cjs +0 -1
  42. package/lib/endpoints/index.cjs +2 -2
  43. package/lib/endpoints/index.d.ts +2 -2
  44. package/lib/endpoints/mcp.cjs +114 -85
  45. package/lib/endpoints/mcp.d.ts +2 -2
  46. package/lib/endpoints/sse.cjs +2 -2
  47. package/lib/endpoints/vue-devtools.cjs +4 -5
  48. package/lib/endpoints/vue-devtools.d.ts +5 -2
  49. package/lib/index.cjs +29 -7
  50. package/package.json +10 -7
  51. package/es/utils/format-bridge.d.ts +0 -9
  52. package/es/utils/format-bridge.mjs +0 -80
  53. package/es/utils/system.d.ts +0 -3
  54. package/es/utils/system.mjs +0 -76
  55. package/lib/utils/format-bridge.cjs +0 -102
  56. package/lib/utils/format-bridge.d.ts +0 -9
  57. package/lib/utils/system.cjs +0 -110
  58. package/lib/utils/system.d.ts +0 -3
@@ -1,4 +1,4 @@
1
- import { SSE_EVENTS_PATH } from "@aipanel/core";
1
+ import { SSE_EVENT_TYPES, SSE_EVENTS_PATH } from "@aipanel/core";
2
2
  import { RequestContext, createLogger } from "@aipanel/core/node";
3
3
  const log = createLogger("Endpoints:SSE");
4
4
  function setupSseEndpoint(server, ctx) {
@@ -12,10 +12,10 @@ function setupSseEndpoint(server, ctx) {
12
12
  });
13
13
  ctx.sseClients.add(res);
14
14
  log.debug("SSE client connected", { totalClients: ctx.sseClients.size });
15
- res.write(`data: ${JSON.stringify({ type: "CONNECTED" })}
15
+ res.write(`data: ${JSON.stringify({ type: SSE_EVENT_TYPES.CONNECTED })}
16
16
 
17
17
  `);
18
- const statusPayload = { type: "STATUS_SYNC" };
18
+ const statusPayload = { type: SSE_EVENT_TYPES.STATUS_SYNC };
19
19
  if (ctx.isServiceStarted !== void 0) {
20
20
  statusPayload.isStarted = ctx.isServiceStarted;
21
21
  }
@@ -4,6 +4,9 @@
4
4
  */
5
5
  import type { ViteDevServer } from "vite";
6
6
  import type { McpProxy } from "../core/mcp-proxy";
7
- export declare const VUE_DEVTOOLS_API_PATH = "/__aipanel_vue_devtools__";
7
+ import { VUE_DEVTOOLS_API_PATH } from "@aipanel/core";
8
+ export { VUE_DEVTOOLS_API_PATH };
8
9
  export declare function setupVueDevtoolsEndpoint(server: ViteDevServer, mcp: McpProxy): void;
9
- export declare function executeAction(action: string, args: Record<string, unknown> | undefined, mcp: McpProxy, projectOrigins: string[]): Promise<unknown>;
10
+ export declare function executeAction(action: string, args: Record<string, unknown> | undefined, mcp: McpProxy,
11
+ /** vue-devtools 桥只注入在项目页面,范围为自动项目页 origins */
12
+ projectOrigins: string[]): Promise<unknown>;
@@ -1,8 +1,7 @@
1
1
  import { createLogger } from "@aipanel/core/node";
2
- import { VUE_DEVTOOLS_ACTIONS } from "@aipanel/core";
2
+ import { VUE_DEVTOOLS_ACTIONS, VUE_DEVTOOLS_API_PATH } from "@aipanel/core";
3
3
  import { getProjectOrigins, validatePageId } from "../core/mcp-chrome.mjs";
4
4
  const log = createLogger("Endpoints:VueDevtools");
5
- const VUE_DEVTOOLS_API_PATH = "/__aipanel_vue_devtools__";
6
5
  function setupVueDevtoolsEndpoint(server, mcp) {
7
6
  server.middlewares.use(VUE_DEVTOOLS_API_PATH, async (req, res) => {
8
7
  res.setHeader("Content-Type", "application/json");
@@ -39,9 +38,9 @@ async function executeAction(action, args, mcp, projectOrigins) {
39
38
  }
40
39
  const validation = await validatePageId(mcp, pageId, projectOrigins);
41
40
  if (!validation.valid) {
42
- log.error("pageId \u65E0\u6548\u6216\u975E\u9879\u76EE\u9875\u9762", {
41
+ log.error("pageId \u65E0\u6548\u6216\u4E0D\u5728\u53EF\u64CD\u4F5C\u8303\u56F4", {
43
42
  pageId,
44
- projectPageIds: validation.projectPages.map((p) => p.pageId)
43
+ allowedPageIds: validation.allowedPages.map((p) => p.pageId)
45
44
  });
46
45
  throw new Error(validation.error);
47
46
  }
package/es/index.mjs CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  CONTEXT_API_PATH,
6
6
  DEFAULT_PROXY_PORT,
7
7
  MCP_API_PATH,
8
+ SESSION_ID_KEY,
8
9
  resolvePluginConfig,
9
10
  setVerbose
10
11
  } from "@aipanel/core";
@@ -14,18 +15,19 @@ import { injectWidget } from "./core/injector.mjs";
14
15
  import { loadProvider } from "./core/provider-loader.mjs";
15
16
  import { AIPanelService } from "./core/service.mjs";
16
17
  import { McpProxy } from "./core/mcp-proxy.mjs";
18
+ import { configureToolScope, extraToolFlag } from "./core/mcp-tools.mjs";
17
19
  import {
18
20
  resolveWidgetPath,
19
21
  resolveWidgetStylePath,
20
22
  resolveVueDevtoolsBridgePath
21
23
  } from "./utils/paths.mjs";
22
- import { findGitRoot } from "./utils/system.mjs";
24
+ import { findGitRoot } from "@aipanel/core/node";
23
25
  const DEVTOOLS_BRIDGE_IMPORTEE = "virtual:aipanel-vue-devtools-bridge";
24
26
  const DEVTOOLS_BRIDGE_QUERY = "aipanel_vue_devtools_bridge";
25
27
  const BRIDGE_SOURCE_PATH = resolveVueDevtoolsBridgePath();
26
28
  const SILENT_CONTEXT_SCRIPT = `<script>
27
29
  (function () {
28
- var API = "/__aipanel_context__";
30
+ var API = "${CONTEXT_API_PATH}";
29
31
  var last = "";
30
32
  function report(force) {
31
33
  if (document.visibilityState !== "visible") return;
@@ -35,7 +37,7 @@ const SILENT_CONTEXT_SCRIPT = `<script>
35
37
  if (!force && key === last) return;
36
38
  last = key;
37
39
  var sessionId = "";
38
- try { sessionId = sessionStorage.getItem("_aipanel_pk") || ""; } catch (e) {}
40
+ try { sessionId = sessionStorage.getItem("${SESSION_ID_KEY}") || ""; } catch (e) {}
39
41
  fetch(API, {
40
42
  method: "POST",
41
43
  headers: { "Content-Type": "application/json" },
@@ -91,7 +93,27 @@ function createAIPanelPlugin(options = {}) {
91
93
  let activeTabId = DEFAULT_TAB;
92
94
  const serviceInstanceId = crypto.randomUUID();
93
95
  const sseClients = /* @__PURE__ */ new Set();
94
- const mcpProxy = new McpProxy({ idleTimeout: 5 * 60 * 1e3 });
96
+ const chromeProjectOptions = config.chromeMcp?.project;
97
+ configureToolScope(
98
+ chromeProjectOptions?.tools?.extra ?? [],
99
+ chromeProjectOptions?.tools?.deny ?? [],
100
+ (msg) => log.warn(msg)
101
+ );
102
+ const chromeManagedArgs = [];
103
+ for (const short of chromeProjectOptions?.tools?.extra ?? []) {
104
+ const flag = extraToolFlag(short);
105
+ if (flag && !chromeManagedArgs.includes(flag)) chromeManagedArgs.push(flag);
106
+ }
107
+ if (chromeProjectOptions?.includeExtensionPages) {
108
+ chromeManagedArgs.push("--experimental-include-all-pages");
109
+ }
110
+ const mcpProxy = new McpProxy({
111
+ idleTimeout: 5 * 60 * 1e3,
112
+ // 用户 chrome MCP 透传:追加 args/env(核心受保护参数不可覆盖,由 McpProxy 过滤)
113
+ userArgs: config.chromeMcp?.args,
114
+ env: config.chromeMcp?.env,
115
+ managedArgs: chromeManagedArgs
116
+ });
95
117
  let provider = null;
96
118
  const service = new AIPanelService(
97
119
  config,
@@ -182,7 +204,8 @@ function createAIPanelPlugin(options = {}) {
182
204
  retryWarmupChromeMcp: () => service.retryWarmupChromeMcp()
183
205
  },
184
206
  mcpProxy,
185
- config.logFiles
207
+ config.logFiles,
208
+ chromeProjectOptions
186
209
  );
187
210
  if (!config.mcpOnly) {
188
211
  try {
@@ -307,7 +330,7 @@ function createAIPanelPlugin(options = {}) {
307
330
  ];
308
331
  const titleInject = `<script>
309
332
  (function () {
310
- var KEY = "_aipanel_pk";
333
+ var KEY = "${SESSION_ID_KEY}";
311
334
  if (!sessionStorage.getItem(KEY)) {
312
335
  sessionStorage.setItem(KEY, "[" + Math.random().toString(36).slice(2, 10) + "]");
313
336
  }