@xiaou66/vite-plugin-vue-mcp-next 0.0.2 → 0.0.5

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/index.d.cts CHANGED
@@ -45,6 +45,8 @@ interface VueMcpNextOptions {
45
45
  readonly dom?: DomOptions;
46
46
  /** Console 日志缓存限制;日志是持续增长数据源,必须防止内存无界增长。 */
47
47
  readonly console?: ConsoleOptions;
48
+ /** Screenshot 配置;CDP 真截图优先,runtime 降级使用 snapdom。 */
49
+ readonly screenshot?: ScreenshotOptions;
48
50
  }
49
51
  /**
50
52
  * Cursor MCP 配置写入策略。
@@ -156,6 +158,146 @@ interface ConsoleOptions {
156
158
  /** 最大日志条数,超过后按先进先出策略丢弃旧日志。 */
157
159
  readonly maxRecords?: number;
158
160
  }
161
+ /**
162
+ * 截图通道选择策略。
163
+ *
164
+ * 页面截图在有 CDP 时应该尽量返回真实浏览器像素;没有 CDP 的开发场景则允许降级到 runtime,
165
+ * 因此这里显式暴露策略,避免调用方误以为所有截图来源都具备同等准确度。
166
+ */
167
+ type ScreenshotPrefer = 'auto' | 'cdp' | 'runtime';
168
+ /**
169
+ * 截图目标范围。
170
+ *
171
+ * 视口、整页和元素截图的坐标来源不同,提前收敛枚举可以让 CDP 与 snapdom 两条通道共享同一套参数校验。
172
+ */
173
+ type ScreenshotTarget = 'viewport' | 'fullPage' | 'element';
174
+ /**
175
+ * 截图输出格式。
176
+ *
177
+ * MCP 返回 base64 数据,格式会直接影响体积;限制为常见浏览器截图格式可以简化大小控制和文档说明。
178
+ */
179
+ type ScreenshotFormat = 'png' | 'jpeg' | 'webp';
180
+ /**
181
+ * snapdom 插件路径对象。
182
+ *
183
+ * 插件函数必须在浏览器 runtime 里通过 Vite import 加载,不能从 Node 侧配置直接序列化过去;
184
+ * 该对象用于描述要加载哪个模块、读取哪个导出,以及是否传入插件工厂参数。
185
+ */
186
+ interface SnapdomPluginImportObject {
187
+ /** Vite import 路径,适用于 `/src/foo.ts`、`@/foo` 这类由 Vite 解析的源码路径。 */
188
+ readonly path: string;
189
+ /** 非默认导出插件时使用,避免强制用户改造已有模块结构。 */
190
+ readonly exportName?: string;
191
+ /** 插件工厂参数,只允许可序列化数据,适合遮罩选择器、水印文案等配置。 */
192
+ readonly options?: unknown;
193
+ }
194
+ /**
195
+ * snapdom 插件导入声明。
196
+ *
197
+ * 字符串覆盖最常见的默认导出插件;对象形式用于已有模块使用命名导出或需要工厂参数的场景。
198
+ */
199
+ type SnapdomPluginImport = string | SnapdomPluginImportObject;
200
+ /**
201
+ * 可安全从 Node 配置传到浏览器 runtime 的 snapdom options。
202
+ *
203
+ * snapdom 原生 options 包含函数型字段;这里仅接收 JSON-safe 部分,函数型能力统一通过 Vite import 路径加载。
204
+ */
205
+ interface JsonSafeSnapdomOptions {
206
+ /** DOM 截图缩放倍率,适合在清晰度和 MCP 响应体积之间取舍。 */
207
+ readonly scale?: number;
208
+ /** 设备像素比覆盖值,适合需要模拟高分屏截图的场景。 */
209
+ readonly dpr?: number;
210
+ /** 输出宽度覆盖值,适合固定截图尺寸的自动化对比场景。 */
211
+ readonly width?: number;
212
+ /** 输出高度覆盖值,适合固定截图尺寸的自动化对比场景。 */
213
+ readonly height?: number;
214
+ /** 背景色兜底,适合页面自身透明但截图需要稳定底色的场景。 */
215
+ readonly backgroundColor?: string;
216
+ /** 有损格式质量,适合控制 jpeg/webp 体积。 */
217
+ readonly quality?: number;
218
+ /** snapdom 资源缓存策略,适合重复截图时减少资源重取成本。 */
219
+ readonly cache?: boolean | 'soft' | 'disabled';
220
+ /** 是否嵌入字体,适合需要尽量还原文本视觉的截图场景。 */
221
+ readonly embedFonts?: boolean;
222
+ /** 是否使用本地字体,适合开发环境字体已安装且希望减少截图资源体积的场景。 */
223
+ readonly localFonts?: boolean;
224
+ /** 跨域资源代理地址,适合图片或字体没有 CORS 但仍希望尽量渲染的场景。 */
225
+ readonly useProxy?: string;
226
+ /** 排除选择器,适合隐藏 token、密码、调试浮层等不应进入截图的元素。 */
227
+ readonly exclude?: string[];
228
+ }
229
+ /**
230
+ * snapdom 降级截图配置。
231
+ *
232
+ * 该配置把可序列化 options 和函数型扩展分开,适用于 Vite 插件 Node 配置需要驱动浏览器 runtime 的场景。
233
+ */
234
+ interface SnapdomScreenshotOptions {
235
+ /** 直接透传给 snapdom 的 JSON-safe options。 */
236
+ readonly options?: JsonSafeSnapdomOptions;
237
+ /** 通过 Vite import 路径加载的插件列表,避免跨 runtime 传函数。 */
238
+ readonly plugins?: SnapdomPluginImport[];
239
+ /** 函数型 filter 的 Vite import 路径,适合复杂元素过滤逻辑。 */
240
+ readonly filter?: string;
241
+ /** 函数型 fallbackURL 的 Vite import 路径,适合按资源 URL 定制兜底图。 */
242
+ readonly fallbackURL?: string;
243
+ }
244
+ /**
245
+ * 页面截图配置。
246
+ *
247
+ * 截图能力同时存在真截图和 DOM 降级截图;集中配置可以让用户明确选择准确度、体积和兼容性边界。
248
+ */
249
+ interface ScreenshotOptions {
250
+ /** 默认截图通道选择,适合项目按运行环境统一控制降级策略。 */
251
+ readonly prefer?: ScreenshotPrefer;
252
+ /** 单次 MCP 返回图片最大字节数,避免 base64 图片挤占上下文或拖慢客户端。 */
253
+ readonly maxBytes?: number;
254
+ /** 无 CDP 时的 snapdom 降级配置。 */
255
+ readonly snapdom?: SnapdomScreenshotOptions;
256
+ }
257
+ /**
258
+ * Runtime 截图请求。
259
+ *
260
+ * MCP 服务端无法直接执行浏览器 DOM 截图,必须通过 Vite RPC 把可序列化配置交给页面 runtime。
261
+ */
262
+ interface RuntimeScreenshotRequest {
263
+ /** 并发请求隔离事件名,适用于多个 MCP 调用同时等待浏览器回传。 */
264
+ readonly event: string;
265
+ /** 截图目标范围,runtime 侧据此选择 document 或 selector 元素。 */
266
+ readonly target: ScreenshotTarget;
267
+ /** 元素截图选择器,只在 `target: "element"` 时需要。 */
268
+ readonly selector?: string;
269
+ /** 输出格式,决定 snapdom 生成 Blob 的 mime type。 */
270
+ readonly format: ScreenshotFormat;
271
+ /** 有损格式质量,适用于控制 jpeg/webp 体积。 */
272
+ readonly quality?: number;
273
+ /** 单次调用缩放倍率覆盖值,适合临时获取高清局部截图。 */
274
+ readonly scale?: number;
275
+ /** 已解析 snapdom 配置,函数型扩展仍以 Vite import 路径表达。 */
276
+ readonly snapdom: Required<Pick<SnapdomScreenshotOptions, 'options' | 'plugins'>> & Omit<SnapdomScreenshotOptions, 'options' | 'plugins'>;
277
+ }
278
+ /**
279
+ * Runtime 截图结果。
280
+ *
281
+ * snapdom 是降级截图路径,结果必须带上限制说明,避免调用方误判为浏览器真实像素。
282
+ */
283
+ interface RuntimeScreenshotResult {
284
+ /** 是否成功,保持与现有 runtime fallback 错误结构一致。 */
285
+ readonly ok: boolean;
286
+ /** 图片 base64 数据,不包含 data URL 前缀,适合 MCP 结构化返回。 */
287
+ readonly data?: string;
288
+ /** 截图宽度,帮助客户端理解图片尺寸和压缩取舍。 */
289
+ readonly width?: number;
290
+ /** 截图高度,帮助客户端理解图片尺寸和压缩取舍。 */
291
+ readonly height?: number;
292
+ /** 图片 mime type,用于 MCP 客户端正确解码。 */
293
+ readonly mimeType?: string;
294
+ /** 原始 Blob 字节数,用于服务端执行 maxBytes 保护。 */
295
+ readonly byteLength?: number;
296
+ /** DOM 截图已知限制,适合在 AI 回答中解释截图不完整原因。 */
297
+ readonly limitations?: string[];
298
+ /** 失败原因,保持浏览器 runtime 错误可读。 */
299
+ readonly error?: string;
300
+ }
159
301
  /**
160
302
  * 解析后的插件配置。
161
303
  *
@@ -186,6 +328,10 @@ interface ResolvedVueMcpNextOptions {
186
328
  readonly dom: Required<DomOptions>;
187
329
  /** 已补齐默认值的 Console 缓存限制。 */
188
330
  readonly console: Required<ConsoleOptions>;
331
+ /** 已补齐默认值的截图配置。 */
332
+ readonly screenshot: Required<Omit<ScreenshotOptions, 'snapdom'>> & {
333
+ readonly snapdom: Required<Pick<SnapdomScreenshotOptions, 'options' | 'plugins'>> & Omit<SnapdomScreenshotOptions, 'options' | 'plugins'>;
334
+ };
189
335
  }
190
336
  /**
191
337
  * MCP 可选择的页面目标。
@@ -353,6 +499,10 @@ interface VueRuntimeRpc {
353
499
  }): void | Promise<void>;
354
500
  /** 回传页面表达式执行结果。 */
355
501
  onEvaluateScriptUpdated(event: string, data: unknown): void;
502
+ /** 通过 snapdom 执行浏览器端 DOM 截图,用于无 CDP 时提供截图降级能力。 */
503
+ takeScreenshot(options: RuntimeScreenshotRequest): void | Promise<void>;
504
+ /** 回传 snapdom 截图结果,使用事件名隔离并发 MCP 请求。 */
505
+ onScreenshotTaken(event: string, data: RuntimeScreenshotResult): void;
356
506
  /** 读取 Vue component inspector tree,用于 `get_component_tree` 工具。 */
357
507
  getInspectorTree(options: {
358
508
  event: string;
package/dist/index.d.ts CHANGED
@@ -45,6 +45,8 @@ interface VueMcpNextOptions {
45
45
  readonly dom?: DomOptions;
46
46
  /** Console 日志缓存限制;日志是持续增长数据源,必须防止内存无界增长。 */
47
47
  readonly console?: ConsoleOptions;
48
+ /** Screenshot 配置;CDP 真截图优先,runtime 降级使用 snapdom。 */
49
+ readonly screenshot?: ScreenshotOptions;
48
50
  }
49
51
  /**
50
52
  * Cursor MCP 配置写入策略。
@@ -156,6 +158,146 @@ interface ConsoleOptions {
156
158
  /** 最大日志条数,超过后按先进先出策略丢弃旧日志。 */
157
159
  readonly maxRecords?: number;
158
160
  }
161
+ /**
162
+ * 截图通道选择策略。
163
+ *
164
+ * 页面截图在有 CDP 时应该尽量返回真实浏览器像素;没有 CDP 的开发场景则允许降级到 runtime,
165
+ * 因此这里显式暴露策略,避免调用方误以为所有截图来源都具备同等准确度。
166
+ */
167
+ type ScreenshotPrefer = 'auto' | 'cdp' | 'runtime';
168
+ /**
169
+ * 截图目标范围。
170
+ *
171
+ * 视口、整页和元素截图的坐标来源不同,提前收敛枚举可以让 CDP 与 snapdom 两条通道共享同一套参数校验。
172
+ */
173
+ type ScreenshotTarget = 'viewport' | 'fullPage' | 'element';
174
+ /**
175
+ * 截图输出格式。
176
+ *
177
+ * MCP 返回 base64 数据,格式会直接影响体积;限制为常见浏览器截图格式可以简化大小控制和文档说明。
178
+ */
179
+ type ScreenshotFormat = 'png' | 'jpeg' | 'webp';
180
+ /**
181
+ * snapdom 插件路径对象。
182
+ *
183
+ * 插件函数必须在浏览器 runtime 里通过 Vite import 加载,不能从 Node 侧配置直接序列化过去;
184
+ * 该对象用于描述要加载哪个模块、读取哪个导出,以及是否传入插件工厂参数。
185
+ */
186
+ interface SnapdomPluginImportObject {
187
+ /** Vite import 路径,适用于 `/src/foo.ts`、`@/foo` 这类由 Vite 解析的源码路径。 */
188
+ readonly path: string;
189
+ /** 非默认导出插件时使用,避免强制用户改造已有模块结构。 */
190
+ readonly exportName?: string;
191
+ /** 插件工厂参数,只允许可序列化数据,适合遮罩选择器、水印文案等配置。 */
192
+ readonly options?: unknown;
193
+ }
194
+ /**
195
+ * snapdom 插件导入声明。
196
+ *
197
+ * 字符串覆盖最常见的默认导出插件;对象形式用于已有模块使用命名导出或需要工厂参数的场景。
198
+ */
199
+ type SnapdomPluginImport = string | SnapdomPluginImportObject;
200
+ /**
201
+ * 可安全从 Node 配置传到浏览器 runtime 的 snapdom options。
202
+ *
203
+ * snapdom 原生 options 包含函数型字段;这里仅接收 JSON-safe 部分,函数型能力统一通过 Vite import 路径加载。
204
+ */
205
+ interface JsonSafeSnapdomOptions {
206
+ /** DOM 截图缩放倍率,适合在清晰度和 MCP 响应体积之间取舍。 */
207
+ readonly scale?: number;
208
+ /** 设备像素比覆盖值,适合需要模拟高分屏截图的场景。 */
209
+ readonly dpr?: number;
210
+ /** 输出宽度覆盖值,适合固定截图尺寸的自动化对比场景。 */
211
+ readonly width?: number;
212
+ /** 输出高度覆盖值,适合固定截图尺寸的自动化对比场景。 */
213
+ readonly height?: number;
214
+ /** 背景色兜底,适合页面自身透明但截图需要稳定底色的场景。 */
215
+ readonly backgroundColor?: string;
216
+ /** 有损格式质量,适合控制 jpeg/webp 体积。 */
217
+ readonly quality?: number;
218
+ /** snapdom 资源缓存策略,适合重复截图时减少资源重取成本。 */
219
+ readonly cache?: boolean | 'soft' | 'disabled';
220
+ /** 是否嵌入字体,适合需要尽量还原文本视觉的截图场景。 */
221
+ readonly embedFonts?: boolean;
222
+ /** 是否使用本地字体,适合开发环境字体已安装且希望减少截图资源体积的场景。 */
223
+ readonly localFonts?: boolean;
224
+ /** 跨域资源代理地址,适合图片或字体没有 CORS 但仍希望尽量渲染的场景。 */
225
+ readonly useProxy?: string;
226
+ /** 排除选择器,适合隐藏 token、密码、调试浮层等不应进入截图的元素。 */
227
+ readonly exclude?: string[];
228
+ }
229
+ /**
230
+ * snapdom 降级截图配置。
231
+ *
232
+ * 该配置把可序列化 options 和函数型扩展分开,适用于 Vite 插件 Node 配置需要驱动浏览器 runtime 的场景。
233
+ */
234
+ interface SnapdomScreenshotOptions {
235
+ /** 直接透传给 snapdom 的 JSON-safe options。 */
236
+ readonly options?: JsonSafeSnapdomOptions;
237
+ /** 通过 Vite import 路径加载的插件列表,避免跨 runtime 传函数。 */
238
+ readonly plugins?: SnapdomPluginImport[];
239
+ /** 函数型 filter 的 Vite import 路径,适合复杂元素过滤逻辑。 */
240
+ readonly filter?: string;
241
+ /** 函数型 fallbackURL 的 Vite import 路径,适合按资源 URL 定制兜底图。 */
242
+ readonly fallbackURL?: string;
243
+ }
244
+ /**
245
+ * 页面截图配置。
246
+ *
247
+ * 截图能力同时存在真截图和 DOM 降级截图;集中配置可以让用户明确选择准确度、体积和兼容性边界。
248
+ */
249
+ interface ScreenshotOptions {
250
+ /** 默认截图通道选择,适合项目按运行环境统一控制降级策略。 */
251
+ readonly prefer?: ScreenshotPrefer;
252
+ /** 单次 MCP 返回图片最大字节数,避免 base64 图片挤占上下文或拖慢客户端。 */
253
+ readonly maxBytes?: number;
254
+ /** 无 CDP 时的 snapdom 降级配置。 */
255
+ readonly snapdom?: SnapdomScreenshotOptions;
256
+ }
257
+ /**
258
+ * Runtime 截图请求。
259
+ *
260
+ * MCP 服务端无法直接执行浏览器 DOM 截图,必须通过 Vite RPC 把可序列化配置交给页面 runtime。
261
+ */
262
+ interface RuntimeScreenshotRequest {
263
+ /** 并发请求隔离事件名,适用于多个 MCP 调用同时等待浏览器回传。 */
264
+ readonly event: string;
265
+ /** 截图目标范围,runtime 侧据此选择 document 或 selector 元素。 */
266
+ readonly target: ScreenshotTarget;
267
+ /** 元素截图选择器,只在 `target: "element"` 时需要。 */
268
+ readonly selector?: string;
269
+ /** 输出格式,决定 snapdom 生成 Blob 的 mime type。 */
270
+ readonly format: ScreenshotFormat;
271
+ /** 有损格式质量,适用于控制 jpeg/webp 体积。 */
272
+ readonly quality?: number;
273
+ /** 单次调用缩放倍率覆盖值,适合临时获取高清局部截图。 */
274
+ readonly scale?: number;
275
+ /** 已解析 snapdom 配置,函数型扩展仍以 Vite import 路径表达。 */
276
+ readonly snapdom: Required<Pick<SnapdomScreenshotOptions, 'options' | 'plugins'>> & Omit<SnapdomScreenshotOptions, 'options' | 'plugins'>;
277
+ }
278
+ /**
279
+ * Runtime 截图结果。
280
+ *
281
+ * snapdom 是降级截图路径,结果必须带上限制说明,避免调用方误判为浏览器真实像素。
282
+ */
283
+ interface RuntimeScreenshotResult {
284
+ /** 是否成功,保持与现有 runtime fallback 错误结构一致。 */
285
+ readonly ok: boolean;
286
+ /** 图片 base64 数据,不包含 data URL 前缀,适合 MCP 结构化返回。 */
287
+ readonly data?: string;
288
+ /** 截图宽度,帮助客户端理解图片尺寸和压缩取舍。 */
289
+ readonly width?: number;
290
+ /** 截图高度,帮助客户端理解图片尺寸和压缩取舍。 */
291
+ readonly height?: number;
292
+ /** 图片 mime type,用于 MCP 客户端正确解码。 */
293
+ readonly mimeType?: string;
294
+ /** 原始 Blob 字节数,用于服务端执行 maxBytes 保护。 */
295
+ readonly byteLength?: number;
296
+ /** DOM 截图已知限制,适合在 AI 回答中解释截图不完整原因。 */
297
+ readonly limitations?: string[];
298
+ /** 失败原因,保持浏览器 runtime 错误可读。 */
299
+ readonly error?: string;
300
+ }
159
301
  /**
160
302
  * 解析后的插件配置。
161
303
  *
@@ -186,6 +328,10 @@ interface ResolvedVueMcpNextOptions {
186
328
  readonly dom: Required<DomOptions>;
187
329
  /** 已补齐默认值的 Console 缓存限制。 */
188
330
  readonly console: Required<ConsoleOptions>;
331
+ /** 已补齐默认值的截图配置。 */
332
+ readonly screenshot: Required<Omit<ScreenshotOptions, 'snapdom'>> & {
333
+ readonly snapdom: Required<Pick<SnapdomScreenshotOptions, 'options' | 'plugins'>> & Omit<SnapdomScreenshotOptions, 'options' | 'plugins'>;
334
+ };
189
335
  }
190
336
  /**
191
337
  * MCP 可选择的页面目标。
@@ -353,6 +499,10 @@ interface VueRuntimeRpc {
353
499
  }): void | Promise<void>;
354
500
  /** 回传页面表达式执行结果。 */
355
501
  onEvaluateScriptUpdated(event: string, data: unknown): void;
502
+ /** 通过 snapdom 执行浏览器端 DOM 截图,用于无 CDP 时提供截图降级能力。 */
503
+ takeScreenshot(options: RuntimeScreenshotRequest): void | Promise<void>;
504
+ /** 回传 snapdom 截图结果,使用事件名隔离并发 MCP 请求。 */
505
+ onScreenshotTaken(event: string, data: RuntimeScreenshotResult): void;
356
506
  /** 读取 Vue component inspector tree,用于 `get_component_tree` 工具。 */
357
507
  getInspectorTree(options: {
358
508
  event: string;