@xiaou66/vite-plugin-vue-mcp-next 1.3.3 → 1.3.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.
@@ -142,153 +142,165 @@ var DEFAULT_OPTIONS = {
142
142
  var import_nanoid = require("nanoid");
143
143
 
144
144
  // src/shared/serialization.ts
145
- var RPC_CIRCULAR_VALUE = "[Circular]";
146
- var RPC_UNREADABLE_VALUE = "[Unreadable]";
147
- function toRpcSafeValue(value) {
148
- return toRpcSafeChildValue(value, createRpcSafeContext(), false);
145
+ var DEFAULT_PREVIEW_OPTIONS = {
146
+ maxDepth: 2,
147
+ maxKeys: 20,
148
+ maxArrayItems: 20,
149
+ maxStringLength: 1e3,
150
+ maxTotalNodes: 200
151
+ };
152
+ var CIRCULAR_VALUE = "[Circular]";
153
+ var TRUNCATED_VALUE = "[Truncated]";
154
+ var UNREADABLE_VALUE = "[Unreadable]";
155
+ function createBoundedPreview(value, options = {}) {
156
+ return previewValue(
157
+ value,
158
+ {
159
+ options: { ...DEFAULT_PREVIEW_OPTIONS, ...options },
160
+ seen: /* @__PURE__ */ new WeakSet(),
161
+ visited: 0
162
+ },
163
+ 0,
164
+ false
165
+ );
149
166
  }
150
167
  function safeStringify(value) {
151
168
  if (typeof value === "string") {
152
- return value;
169
+ return truncateString(value, DEFAULT_PREVIEW_OPTIONS.maxStringLength);
153
170
  }
154
- const safeValue = toRpcSafeValue(value);
155
- return safeValue === void 0 ? "undefined" : JSON.stringify(safeValue);
156
- }
157
- function createRpcSafeContext() {
158
- return {
159
- cache: /* @__PURE__ */ new WeakMap(),
160
- seen: /* @__PURE__ */ new WeakSet()
161
- };
171
+ const preview = createBoundedPreview(value);
172
+ if (preview === void 0) {
173
+ return "undefined";
174
+ }
175
+ return JSON.stringify(preview);
162
176
  }
163
- function toRpcSafeChildValue(value, context, arrayItem) {
177
+ function previewValue(value, context, depth, arrayItem) {
164
178
  if (value === null) {
165
179
  return null;
166
180
  }
167
181
  switch (typeof value) {
168
182
  case "string":
169
- case "boolean":
170
- return value;
183
+ return truncateString(value, context.options.maxStringLength);
171
184
  case "number":
172
185
  return Number.isFinite(value) ? value : String(value);
186
+ case "boolean":
187
+ return value;
173
188
  case "bigint":
174
189
  return value.toString();
175
190
  case "symbol":
176
- return toSymbolPlaceholder(value);
177
- case "undefined":
191
+ return value.description ? `[Symbol(${value.description})]` : "[Symbol]";
178
192
  case "function":
193
+ return functionLabel(value);
194
+ case "undefined":
179
195
  return arrayItem ? null : void 0;
180
196
  case "object":
181
- return toRpcSafeObject(value, context);
197
+ return previewObject(value, context, depth);
182
198
  default:
183
199
  return arrayItem ? null : void 0;
184
200
  }
185
201
  }
186
- function toRpcSafeObject(value, context) {
202
+ function previewObject(value, context, depth) {
187
203
  if (context.seen.has(value)) {
188
- return RPC_CIRCULAR_VALUE;
204
+ return CIRCULAR_VALUE;
189
205
  }
190
- const cached = context.cache.get(value);
191
- if (cached) {
192
- return cached;
206
+ if (context.visited >= context.options.maxTotalNodes) {
207
+ return TRUNCATED_VALUE;
193
208
  }
209
+ if (depth >= context.options.maxDepth) {
210
+ return objectLabel(value);
211
+ }
212
+ context.visited += 1;
194
213
  context.seen.add(value);
195
- try {
196
- let safeValue;
197
- if (value instanceof Date) {
198
- safeValue = toSafeDate(value);
199
- } else if (value instanceof Error) {
200
- safeValue = toSafeError(value, context);
201
- } else if (Array.isArray(value)) {
202
- safeValue = toSafeArray(value, context);
203
- } else {
204
- safeValue = toSafeRecord(value, context);
205
- }
206
- context.cache.set(value, safeValue);
207
- return safeValue;
208
- } finally {
209
- context.seen.delete(value);
214
+ if (value instanceof Date) {
215
+ return Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
216
+ }
217
+ if (value instanceof Error) {
218
+ return previewError(value, context, depth);
219
+ }
220
+ if (Array.isArray(value)) {
221
+ return previewArray(value, context, depth);
222
+ }
223
+ if (isElementLike(value)) {
224
+ return elementLabel(value);
210
225
  }
226
+ return previewRecord(value, context, depth);
211
227
  }
212
- function toSafeArray(values, context) {
213
- return values.map((item) => toRpcSafeChildValue(item, context, true) ?? null);
228
+ function previewArray(values, context, depth) {
229
+ const result = values.slice(0, context.options.maxArrayItems).map((item) => previewValue(item, context, depth + 1, true) ?? null);
230
+ if (values.length > context.options.maxArrayItems) {
231
+ result.push(TRUNCATED_VALUE);
232
+ }
233
+ return result;
214
234
  }
215
- function toSafeRecord(value, context) {
216
- const keys = getEnumerableKeys(value);
235
+ function previewRecord(value, context, depth) {
236
+ const keys = enumerableKeys(value);
217
237
  if (!keys) {
218
- return RPC_UNREADABLE_VALUE;
219
- }
220
- if (keys.length === 0 && !isPlainRecord(value)) {
221
- return toObjectSummary(value);
238
+ return UNREADABLE_VALUE;
222
239
  }
223
240
  const result = {};
224
- keys.forEach((key) => {
225
- if (key === "toJSON") {
226
- return;
227
- }
228
- const field = readObjectField(value, key);
229
- if (!field.ok) {
230
- result[key] = RPC_UNREADABLE_VALUE;
231
- return;
232
- }
233
- const safeValue = toRpcSafeChildValue(field.value, context, false);
234
- if (safeValue !== void 0) {
235
- result[key] = safeValue;
236
- }
241
+ const limitedKeys = keys.filter((key) => key !== "toJSON");
242
+ limitedKeys.slice(0, context.options.maxKeys).forEach((key) => {
243
+ const field = readField(value, key);
244
+ result[key] = field.ok ? previewValue(field.value, context, depth + 1, false) ?? null : UNREADABLE_VALUE;
237
245
  });
246
+ if (limitedKeys.length > context.options.maxKeys) {
247
+ result[TRUNCATED_VALUE] = `${String(limitedKeys.length - context.options.maxKeys)} keys omitted`;
248
+ }
238
249
  return result;
239
250
  }
240
- function toSafeError(error, context) {
251
+ function previewError(error, context, depth) {
241
252
  const result = {
242
253
  name: error.name,
243
- message: error.message
254
+ message: truncateString(error.message, context.options.maxStringLength)
244
255
  };
245
- const stack = readObjectField(error, "stack");
256
+ const stack = readField(error, "stack");
246
257
  if (stack.ok && typeof stack.value === "string") {
247
- result.stack = stack.value;
258
+ result.stack = truncateString(stack.value, context.options.maxStringLength);
248
259
  }
249
- if ("cause" in error) {
250
- const cause = readObjectField(error, "cause");
251
- result.cause = cause.ok ? toRpcSafeChildValue(cause.value, context, false) ?? null : RPC_UNREADABLE_VALUE;
260
+ const cause = readField(error, "cause");
261
+ if (cause.ok && cause.value !== void 0) {
262
+ result.cause = previewValue(cause.value, context, depth + 1, false) ?? null;
252
263
  }
253
264
  return result;
254
265
  }
255
- function toSafeDate(value) {
256
- return Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
257
- }
258
- function getEnumerableKeys(value) {
266
+ function enumerableKeys(value) {
259
267
  try {
260
268
  return Object.keys(value);
261
269
  } catch {
262
270
  return void 0;
263
271
  }
264
272
  }
265
- function readObjectField(value, key) {
273
+ function readField(value, key) {
266
274
  try {
267
- return {
268
- ok: true,
269
- value: value[key]
270
- };
275
+ return { ok: true, value: value[key] };
271
276
  } catch {
272
277
  return { ok: false };
273
278
  }
274
279
  }
275
- function isPlainRecord(value) {
276
- try {
277
- const prototype = Object.getPrototypeOf(value);
278
- return prototype === Object.prototype || prototype === null;
279
- } catch {
280
- return false;
280
+ function truncateString(value, maxLength) {
281
+ if (value.length <= maxLength) {
282
+ return value;
281
283
  }
284
+ return `${value.slice(0, maxLength)}${TRUNCATED_VALUE}`;
282
285
  }
283
- function toObjectSummary(value) {
284
- try {
285
- return Object.prototype.toString.call(value);
286
- } catch {
287
- return "[Object]";
286
+ function functionLabel(value) {
287
+ return value.name ? `[Function:${value.name}]` : "[Function]";
288
+ }
289
+ function objectLabel(value) {
290
+ if (Array.isArray(value)) {
291
+ return `[Array(${String(value.length)})]`;
288
292
  }
293
+ return "[Object]";
289
294
  }
290
- function toSymbolPlaceholder(value) {
291
- return value.description ? `[Symbol(${value.description})]` : "[Symbol]";
295
+ function isElementLike(value) {
296
+ const node = value;
297
+ return node.nodeType === 1 && typeof node.nodeName === "string";
298
+ }
299
+ function elementLabel(value) {
300
+ const name = value.nodeName.toLowerCase();
301
+ const id = value.id ? `#${value.id}` : "";
302
+ const className = typeof value.className === "string" && value.className ? `.${value.className.trim().replace(/\s+/g, ".")}` : "";
303
+ return `[Element:${name}${id}${className}]`;
292
304
  }
293
305
 
294
306
  // src/runtime/consoleHook.ts
@@ -301,14 +313,13 @@ function installConsoleHook(options) {
301
313
  debug: console.debug
302
314
  };
303
315
  const emit = (level, args) => {
304
- const serializedArgs = serializeConsoleArgs(args);
305
316
  options.send({
306
317
  id: (0, import_nanoid.nanoid)(),
307
318
  pageId: options.pageId,
308
319
  source: "hook",
309
320
  level,
310
- message: serializedArgs.join(" "),
311
- args: serializedArgs,
321
+ message: args.map((arg) => safeStringify(arg)).join(" "),
322
+ args: args.map((arg) => createBoundedPreview(arg)),
312
323
  timestamp: Date.now()
313
324
  });
314
325
  };
@@ -335,9 +346,6 @@ function installConsoleHook(options) {
335
346
  window.removeEventListener("error", onError);
336
347
  };
337
348
  }
338
- function serializeConsoleArgs(args) {
339
- return args.map((arg) => safeStringify(arg));
340
- }
341
349
 
342
350
  // src/runtime/elementRegistry.ts
343
351
  var import_nanoid2 = require("nanoid");
@@ -401,7 +409,7 @@ function installElementPicker(options) {
401
409
  window.addEventListener(
402
410
  "click",
403
411
  (event) => {
404
- if (!active || !isElementLike(event.target)) {
412
+ if (!active || !isElementLike2(event.target)) {
405
413
  return;
406
414
  }
407
415
  event.preventDefault();
@@ -483,7 +491,7 @@ function showToast(message, durationMs) {
483
491
  toast.remove();
484
492
  }, durationMs);
485
493
  }
486
- function isElementLike(value) {
494
+ function isElementLike2(value) {
487
495
  return Boolean(
488
496
  value && typeof value === "object" && "getAttribute" in value && "getBoundingClientRect" in value
489
497
  );
@@ -2152,6 +2160,18 @@ function createRuntimeDevtoolsRpc(getRpc) {
2152
2160
  var PINIA_INSPECTOR_ID = "pinia";
2153
2161
  var COMPONENTS_INSPECTOR_ID = "components";
2154
2162
  var COMPONENT_HIGHLIGHT_DURATION = 5e3;
2163
+ var INSPECTOR_TREE_MAX_DEPTH = 20;
2164
+ var INSPECTOR_TREE_MAX_NODES = 500;
2165
+ var INSPECTOR_TREE_MAX_CHILDREN = 200;
2166
+ var INSPECTOR_TREE_MAX_TAGS = 20;
2167
+ var INSPECTOR_NODE_FIELDS = [
2168
+ "id",
2169
+ "label",
2170
+ "name",
2171
+ "inactive",
2172
+ "isFragment",
2173
+ "autoOpen"
2174
+ ];
2155
2175
  var highlightComponentTimeout;
2156
2176
  function initializeVueDevtoolsHook() {
2157
2177
  import_devtools_kit.devtools.init();
@@ -2171,14 +2191,64 @@ function installVueBridge(hot) {
2171
2191
  );
2172
2192
  rpcRef.current = rpc;
2173
2193
  }
2174
- function toVueRpcPayload(value) {
2175
- return toRpcSafeValue(value);
2194
+ function projectInspectorTreeList(value) {
2195
+ if (!Array.isArray(value)) {
2196
+ return [];
2197
+ }
2198
+ const budget = { visited: 0 };
2199
+ return value.map((node) => projectInspectorNode(node, budget, 0));
2200
+ }
2201
+ function projectInspectorNode(value, budget, depth) {
2202
+ if (!value || typeof value !== "object") {
2203
+ return value;
2204
+ }
2205
+ if (budget.visited >= INSPECTOR_TREE_MAX_NODES || depth >= INSPECTOR_TREE_MAX_DEPTH) {
2206
+ return "[Truncated]";
2207
+ }
2208
+ budget.visited += 1;
2209
+ const result = {};
2210
+ INSPECTOR_NODE_FIELDS.forEach((field) => {
2211
+ const valueField = readInspectorField(value, field);
2212
+ if (valueField.ok && isInspectorPrimitive(valueField.value)) {
2213
+ result[field] = valueField.value;
2214
+ }
2215
+ });
2216
+ const tags = readInspectorField(value, "tags");
2217
+ if (tags.ok && Array.isArray(tags.value)) {
2218
+ result.tags = tags.value.slice(0, INSPECTOR_TREE_MAX_TAGS).map(projectInspectorTag);
2219
+ }
2220
+ const children = readInspectorField(value, "children");
2221
+ if (children.ok && Array.isArray(children.value)) {
2222
+ const projectedChildren = children.value.slice(0, INSPECTOR_TREE_MAX_CHILDREN).map((child) => projectInspectorNode(child, budget, depth + 1));
2223
+ if (children.value.length > INSPECTOR_TREE_MAX_CHILDREN) {
2224
+ projectedChildren.push("[Truncated]");
2225
+ }
2226
+ result.children = projectedChildren;
2227
+ }
2228
+ return result;
2229
+ }
2230
+ function projectInspectorTag(value) {
2231
+ if (!value || typeof value !== "object") {
2232
+ return value;
2233
+ }
2234
+ const result = {};
2235
+ Object.keys(value).filter((key) => key !== "toJSON").slice(0, 8).forEach((key) => {
2236
+ const field = readInspectorField(value, key);
2237
+ if (field.ok && isInspectorPrimitive(field.value)) {
2238
+ result[key] = field.value;
2239
+ }
2240
+ });
2241
+ return result;
2176
2242
  }
2177
- function toVueRpcJsonPayload(value) {
2178
- return JSON.stringify(toRpcSafeValue(value) ?? null);
2243
+ function readInspectorField(value, key) {
2244
+ try {
2245
+ return { ok: true, value: value[key] };
2246
+ } catch {
2247
+ return { ok: false };
2248
+ }
2179
2249
  }
2180
- function toVueRpcPrettyJsonPayload(value) {
2181
- return JSON.stringify(toRpcSafeValue(value), null, 2);
2250
+ function isInspectorPrimitive(value) {
2251
+ return typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null;
2182
2252
  }
2183
2253
  function createClientVueRuntimeRpc(getRpc) {
2184
2254
  return {
@@ -2190,7 +2260,7 @@ function createClientVueRuntimeRpc(getRpc) {
2190
2260
  });
2191
2261
  getRpc().onInspectorTreeUpdated(
2192
2262
  query.event,
2193
- toVueRpcPayload(inspectorTree[0])
2263
+ projectInspectorNode(inspectorTree[0], { visited: 0 }, 0)
2194
2264
  );
2195
2265
  },
2196
2266
  onInspectorTreeUpdated: () => void 0,
@@ -2199,7 +2269,7 @@ function createClientVueRuntimeRpc(getRpc) {
2199
2269
  if (!targetNode) {
2200
2270
  getRpc().onInspectorStateUpdated(
2201
2271
  query.event,
2202
- toVueRpcPayload(createMissingComponentError(query.componentName))
2272
+ createMissingComponentError(query.componentName)
2203
2273
  );
2204
2274
  return;
2205
2275
  }
@@ -2207,10 +2277,7 @@ function createClientVueRuntimeRpc(getRpc) {
2207
2277
  inspectorId: COMPONENTS_INSPECTOR_ID,
2208
2278
  nodeId: targetNode.id
2209
2279
  });
2210
- getRpc().onInspectorStateUpdated(
2211
- query.event,
2212
- toVueRpcJsonPayload(inspectorState)
2213
- );
2280
+ getRpc().onInspectorStateUpdated(query.event, (0, import_devtools_kit.stringify)(inspectorState));
2214
2281
  },
2215
2282
  onInspectorStateUpdated: () => void 0,
2216
2283
  async editComponentState(query) {
@@ -2247,7 +2314,7 @@ function createClientVueRuntimeRpc(getRpc) {
2247
2314
  getRouterInfo(query) {
2248
2315
  getRpc().onRouterInfoUpdated(
2249
2316
  query.event,
2250
- toVueRpcPrettyJsonPayload(import_devtools_kit.devtoolsRouterInfo)
2317
+ JSON.stringify(import_devtools_kit.devtoolsRouterInfo, null, 2)
2251
2318
  );
2252
2319
  },
2253
2320
  onRouterInfoUpdated: () => void 0,
@@ -2258,7 +2325,10 @@ function createClientVueRuntimeRpc(getRpc) {
2258
2325
  filter: ""
2259
2326
  })
2260
2327
  );
2261
- getRpc().onPiniaTreeUpdated(query.event, toVueRpcPayload(inspectorTree));
2328
+ getRpc().onPiniaTreeUpdated(
2329
+ query.event,
2330
+ projectInspectorTreeList(inspectorTree)
2331
+ );
2262
2332
  },
2263
2333
  onPiniaTreeUpdated: () => void 0,
2264
2334
  async getPiniaState(query) {
@@ -2273,7 +2343,7 @@ function createClientVueRuntimeRpc(getRpc) {
2273
2343
  }
2274
2344
  return import_devtools_kit.devtools.ctx.api.getInspectorState(payload);
2275
2345
  });
2276
- getRpc().onPiniaInfoUpdated(query.event, toVueRpcJsonPayload(result));
2346
+ getRpc().onPiniaInfoUpdated(query.event, (0, import_devtools_kit.stringify)(result));
2277
2347
  },
2278
2348
  onPiniaInfoUpdated: () => void 0,
2279
2349
  async recordPerformance(query) {
@@ -2281,7 +2351,7 @@ function createClientVueRuntimeRpc(getRpc) {
2281
2351
  if (!collector) {
2282
2352
  getRpc().onPerformanceRecorded(
2283
2353
  query.event,
2284
- toVueRpcPayload(createPerformanceUnavailableError())
2354
+ createPerformanceUnavailableError()
2285
2355
  );
2286
2356
  return;
2287
2357
  }
@@ -2291,11 +2361,11 @@ function createClientVueRuntimeRpc(getRpc) {
2291
2361
  includeMemory: query.includeMemory,
2292
2362
  includeStacks: query.includeStacks
2293
2363
  });
2294
- getRpc().onPerformanceRecorded(query.event, toVueRpcPayload(report));
2364
+ getRpc().onPerformanceRecorded(query.event, report);
2295
2365
  } catch (error) {
2296
2366
  getRpc().onPerformanceRecorded(
2297
2367
  query.event,
2298
- toVueRpcPayload(createPerformanceError(error))
2368
+ createPerformanceError(error)
2299
2369
  );
2300
2370
  }
2301
2371
  },
@@ -2305,7 +2375,7 @@ function createClientVueRuntimeRpc(getRpc) {
2305
2375
  if (!collector) {
2306
2376
  getRpc().onPerformanceRecordingStarted(
2307
2377
  query.event,
2308
- toVueRpcPayload(createPerformanceUnavailableError())
2378
+ createPerformanceUnavailableError()
2309
2379
  );
2310
2380
  return;
2311
2381
  }
@@ -2314,19 +2384,16 @@ function createClientVueRuntimeRpc(getRpc) {
2314
2384
  includeMemory: query.includeMemory,
2315
2385
  includeStacks: query.includeStacks
2316
2386
  });
2317
- getRpc().onPerformanceRecordingStarted(
2318
- query.event,
2319
- toVueRpcPayload({
2320
- ok: true,
2321
- recordingId,
2322
- startedAt: Date.now(),
2323
- source: "hook"
2324
- })
2325
- );
2387
+ getRpc().onPerformanceRecordingStarted(query.event, {
2388
+ ok: true,
2389
+ recordingId,
2390
+ startedAt: Date.now(),
2391
+ source: "hook"
2392
+ });
2326
2393
  } catch (error) {
2327
2394
  getRpc().onPerformanceRecordingStarted(
2328
2395
  query.event,
2329
- toVueRpcPayload(createPerformanceError(error))
2396
+ createPerformanceError(error)
2330
2397
  );
2331
2398
  }
2332
2399
  },
@@ -2336,20 +2403,17 @@ function createClientVueRuntimeRpc(getRpc) {
2336
2403
  if (!collector) {
2337
2404
  getRpc().onPerformanceRecordingStopped(
2338
2405
  query.event,
2339
- toVueRpcPayload(createPerformanceUnavailableError())
2406
+ createPerformanceUnavailableError()
2340
2407
  );
2341
2408
  return;
2342
2409
  }
2343
2410
  try {
2344
2411
  const report = collector.stop(query.recordingId);
2345
- getRpc().onPerformanceRecordingStopped(
2346
- query.event,
2347
- toVueRpcPayload(report)
2348
- );
2412
+ getRpc().onPerformanceRecordingStopped(query.event, report);
2349
2413
  } catch (error) {
2350
2414
  getRpc().onPerformanceRecordingStopped(
2351
2415
  query.event,
2352
- toVueRpcPayload(createPerformanceError(error))
2416
+ createPerformanceError(error)
2353
2417
  );
2354
2418
  }
2355
2419
  },