@xiaou66/vite-plugin-vue-mcp-next 1.3.6 → 1.3.7

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.
@@ -1,4 +1,4 @@
1
- import { h as RuntimeClientOptions } from '../types-Ct73MnH0.cjs';
1
+ import { h as RuntimeClientOptions } from '../types-DA9dLKJ8.cjs';
2
2
  import 'hookable';
3
3
  import 'vite';
4
4
 
@@ -1,4 +1,4 @@
1
- import { h as RuntimeClientOptions } from '../types-Ct73MnH0.js';
1
+ import { h as RuntimeClientOptions } from '../types-DA9dLKJ8.js';
2
2
  import 'hookable';
3
3
  import 'vite';
4
4
 
@@ -112,7 +112,7 @@ var DEFAULT_OPTIONS = {
112
112
  };
113
113
 
114
114
  // src/runtime/consoleHook.ts
115
- import { nanoid } from "nanoid";
115
+ import { nanoid as nanoid2 } from "nanoid";
116
116
 
117
117
  // src/shared/serialization.ts
118
118
  var DEFAULT_PREVIEW_OPTIONS = {
@@ -276,7 +276,56 @@ function elementLabel(value) {
276
276
  return `[Element:${name}${id}${className}]`;
277
277
  }
278
278
 
279
+ // src/runtime/consoleArgRegistry.ts
280
+ import { nanoid } from "nanoid";
281
+ var CONSOLE_ARG_ID_PREFIX = "console-arg-";
282
+ var MAX_CONSOLE_ARG_REFERENCES = 200;
283
+ var consoleArgReferences = /* @__PURE__ */ new Map();
284
+ function registerConsoleArg(value) {
285
+ const argId = `${CONSOLE_ARG_ID_PREFIX}${nanoid()}`;
286
+ const kind = Array.isArray(value) ? "array" : "object";
287
+ const label = `[${kind === "array" ? "Array" : "Object"}:${argId}]`;
288
+ consoleArgReferences.set(argId, value);
289
+ trimConsoleArgReferences();
290
+ return { type: "object", kind, argId, label };
291
+ }
292
+ function inspectConsoleArg(request) {
293
+ if (!consoleArgReferences.has(request.argId)) {
294
+ return {
295
+ ok: false,
296
+ argId: request.argId,
297
+ error: "Console object reference not found or expired"
298
+ };
299
+ }
300
+ return {
301
+ ok: true,
302
+ argId: request.argId,
303
+ preview: createBoundedPreview(consoleArgReferences.get(request.argId), {
304
+ maxDepth: request.maxDepth,
305
+ maxKeys: request.maxKeys,
306
+ maxArrayItems: request.maxArrayItems,
307
+ maxStringLength: request.maxStringLength,
308
+ maxTotalNodes: request.maxTotalNodes
309
+ })
310
+ };
311
+ }
312
+ function trimConsoleArgReferences() {
313
+ while (consoleArgReferences.size > MAX_CONSOLE_ARG_REFERENCES) {
314
+ const [oldestArgId] = consoleArgReferences.keys();
315
+ if (!oldestArgId) {
316
+ return;
317
+ }
318
+ consoleArgReferences.delete(oldestArgId);
319
+ }
320
+ }
321
+
279
322
  // src/runtime/consoleHook.ts
323
+ var MAX_MESSAGE_CHAR_LENGTH = 5e3;
324
+ var MAX_CONSECUTIVE_DUPLICATES = 50;
325
+ var MAX_SKIPPED_COUNT = 500;
326
+ var DEDUPE_ARG_SAMPLE_COUNT = 3;
327
+ var DEDUPE_STRING_PREFIX_LENGTH = 80;
328
+ var MAX_ARGUMENT_PREVIEW_COUNT = 3;
280
329
  function installConsoleHook(options) {
281
330
  const originalConsole = {
282
331
  log: console.log,
@@ -285,14 +334,36 @@ function installConsoleHook(options) {
285
334
  error: console.error,
286
335
  debug: console.debug
287
336
  };
337
+ let duplicateState;
288
338
  const emit = (level, args) => {
339
+ const dedupe = createDedupeInfo(level, args);
340
+ if (duplicateState?.key === dedupe.key) {
341
+ duplicateState.count++;
342
+ if (duplicateState.count > MAX_CONSECUTIVE_DUPLICATES) {
343
+ duplicateState.skipped = Math.min(
344
+ duplicateState.skipped + 1,
345
+ MAX_SKIPPED_COUNT
346
+ );
347
+ return;
348
+ }
349
+ } else {
350
+ flushSuppressedSummary(options, duplicateState);
351
+ duplicateState = {
352
+ key: dedupe.key,
353
+ level,
354
+ label: dedupe.label,
355
+ count: 1,
356
+ skipped: 0
357
+ };
358
+ }
359
+ const payload = createConsolePayload(args);
289
360
  options.send({
290
- id: nanoid(),
361
+ id: nanoid2(),
291
362
  pageId: options.pageId,
292
363
  source: "hook",
293
364
  level,
294
- message: args.map((arg) => safeStringify(arg)).join(" "),
295
- args: args.map((arg) => createBoundedPreview(arg)),
365
+ message: payload.message,
366
+ args: payload.args,
296
367
  timestamp: Date.now()
297
368
  });
298
369
  };
@@ -304,7 +375,7 @@ function installConsoleHook(options) {
304
375
  });
305
376
  const onError = (event) => {
306
377
  options.send({
307
- id: nanoid(),
378
+ id: nanoid2(),
308
379
  pageId: options.pageId,
309
380
  source: "hook",
310
381
  level: "error",
@@ -315,18 +386,145 @@ function installConsoleHook(options) {
315
386
  };
316
387
  window.addEventListener("error", onError);
317
388
  return () => {
389
+ flushSuppressedSummary(options, duplicateState);
390
+ duplicateState = void 0;
318
391
  Object.assign(console, originalConsole);
319
392
  window.removeEventListener("error", onError);
320
393
  };
321
394
  }
395
+ function createDedupeInfo(level, args) {
396
+ const signatures = args.slice(0, DEDUPE_ARG_SAMPLE_COUNT).map((arg) => createValueSignature(arg));
397
+ const key = `${level}:${signatures.join("|")}`;
398
+ const label = createDedupeLabel(args, signatures);
399
+ return { key, label };
400
+ }
401
+ function createDedupeLabel(args, signatures) {
402
+ const [firstArg] = args;
403
+ if (typeof firstArg === "string") {
404
+ return sliceDedupeString(firstArg);
405
+ }
406
+ return signatures.join(" ") || "[empty]";
407
+ }
408
+ function createConsolePayload(args) {
409
+ const entries = args.map(createArgEntry);
410
+ const rawMessage = entries.map((entry) => entry.message).join(" ");
411
+ const oversizedInput = args.some(isOversizedString);
412
+ const oversizedMessage = rawMessage.length > MAX_MESSAGE_CHAR_LENGTH;
413
+ const message = oversizedMessage ? `${rawMessage.slice(0, MAX_MESSAGE_CHAR_LENGTH)}[Truncated]` : rawMessage;
414
+ const includeArgs = !oversizedInput && !oversizedMessage;
415
+ return {
416
+ message,
417
+ args: includeArgs ? entries.slice(0, MAX_ARGUMENT_PREVIEW_COUNT).map((entry) => entry.preview) : []
418
+ };
419
+ }
420
+ function createArgEntry(value) {
421
+ if (typeof value === "string") {
422
+ return {
423
+ message: truncateMessageString(value),
424
+ preview: value
425
+ };
426
+ }
427
+ if (value && typeof value === "object") {
428
+ const reference = registerConsoleArg(value);
429
+ return {
430
+ message: reference.label,
431
+ preview: reference
432
+ };
433
+ }
434
+ const preview = createPrimitivePreview(value);
435
+ return {
436
+ message: safeStringify(value),
437
+ preview
438
+ };
439
+ }
440
+ function createPrimitivePreview(value) {
441
+ if (value === null) {
442
+ return null;
443
+ }
444
+ if (typeof value === "number") {
445
+ return Number.isFinite(value) ? value : String(value);
446
+ }
447
+ if (typeof value === "bigint") {
448
+ return value.toString();
449
+ }
450
+ if (typeof value === "symbol") {
451
+ return value.description ? `[Symbol(${value.description})]` : "[Symbol]";
452
+ }
453
+ if (typeof value === "function") {
454
+ return value.name ? `[Function:${value.name}]` : "[Function]";
455
+ }
456
+ return value;
457
+ }
458
+ function flushSuppressedSummary(options, state) {
459
+ if (!state || state.skipped === 0) {
460
+ return;
461
+ }
462
+ const skipped = state.skipped >= MAX_SKIPPED_COUNT ? `${String(MAX_SKIPPED_COUNT)}+` : String(state.skipped);
463
+ options.send({
464
+ id: nanoid2(),
465
+ pageId: options.pageId,
466
+ source: "hook",
467
+ level: state.level,
468
+ message: `Suppressed ${skipped} duplicate ${state.level} logs: ${state.label}`,
469
+ args: [],
470
+ timestamp: Date.now()
471
+ });
472
+ }
473
+ function createValueSignature(value) {
474
+ if (value && typeof value === "object") {
475
+ return createObjectTypeLabel(value);
476
+ }
477
+ return createPrimitiveSignature(value);
478
+ }
479
+ function createObjectTypeLabel(value) {
480
+ if (Array.isArray(value)) {
481
+ return "[Array]";
482
+ }
483
+ return "[Object]";
484
+ }
485
+ function createPrimitiveSignature(value) {
486
+ if (typeof value === "string") {
487
+ return `string:${sliceDedupeString(value)}`;
488
+ }
489
+ if (value === null) {
490
+ return "null";
491
+ }
492
+ switch (typeof value) {
493
+ case "number":
494
+ case "boolean":
495
+ case "bigint":
496
+ case "undefined":
497
+ return `${typeof value}:${String(value)}`;
498
+ case "symbol":
499
+ return value.description ? `symbol:${sliceDedupeString(value.description)}` : "symbol";
500
+ case "function":
501
+ return value.name ? `function:${sliceDedupeString(value.name)}` : "function";
502
+ case "object":
503
+ return `object:${Object.prototype.toString.call(value)}`;
504
+ default:
505
+ return "unknown";
506
+ }
507
+ }
508
+ function isOversizedString(value) {
509
+ return typeof value === "string" && value.length > MAX_MESSAGE_CHAR_LENGTH;
510
+ }
511
+ function truncateMessageString(value) {
512
+ if (value.length <= MAX_MESSAGE_CHAR_LENGTH) {
513
+ return value;
514
+ }
515
+ return `${value.slice(0, MAX_MESSAGE_CHAR_LENGTH)}[Truncated]`;
516
+ }
517
+ function sliceDedupeString(value) {
518
+ return value.slice(0, DEDUPE_STRING_PREFIX_LENGTH);
519
+ }
322
520
 
323
521
  // src/runtime/elementRegistry.ts
324
- import { nanoid as nanoid2 } from "nanoid";
522
+ import { nanoid as nanoid3 } from "nanoid";
325
523
  var RUNTIME_ELEMENT_ID_PREFIX = "runtime:vmcp_";
326
524
  var RUNTIME_ELEMENT_ID_SIZE = 8;
327
525
  var runtimeElementRegistry = createRuntimeElementRegistry();
328
526
  function createRuntimeElementId() {
329
- return `${RUNTIME_ELEMENT_ID_PREFIX}${nanoid2(RUNTIME_ELEMENT_ID_SIZE)}`;
527
+ return `${RUNTIME_ELEMENT_ID_PREFIX}${nanoid3(RUNTIME_ELEMENT_ID_SIZE)}`;
330
528
  }
331
529
  function createRuntimeElementRegistry() {
332
530
  const records = /* @__PURE__ */ new Map();
@@ -827,7 +1025,7 @@ function escapeSelector(value) {
827
1025
  }
828
1026
 
829
1027
  // src/runtime/networkHook.ts
830
- import { nanoid as nanoid3 } from "nanoid";
1028
+ import { nanoid as nanoid4 } from "nanoid";
831
1029
 
832
1030
  // src/shared/url.ts
833
1031
  function parseRequestQuery(url) {
@@ -858,7 +1056,7 @@ function safeUrlPathname(url) {
858
1056
  // src/runtime/networkHook.ts
859
1057
  function createHookNetworkRecord(input) {
860
1058
  return {
861
- id: nanoid3(),
1059
+ id: nanoid4(),
862
1060
  pageId: input.pageId,
863
1061
  source: "hook",
864
1062
  url: input.url,
@@ -1013,12 +1211,12 @@ function safeReadXhrResponseText(xhr) {
1013
1211
  }
1014
1212
 
1015
1213
  // src/runtime/pageIdentity.ts
1016
- import { nanoid as nanoid4 } from "nanoid";
1214
+ import { nanoid as nanoid5 } from "nanoid";
1017
1215
  var RUNTIME_CLIENT_ID_STORAGE_KEY = "vite-plugin-vue-mcp-next:runtime-client-id";
1018
1216
  var RUNTIME_CLIENT_ID_WINDOW_NAME_PREFIX = "vite-plugin-vue-mcp-next:runtime-client-id=";
1019
1217
  var RUNTIME_CLIENT_ID_WINDOW_NAME_SEPARATOR = "\n";
1020
1218
  function createRuntimeClientId() {
1021
- return `runtime-client-${nanoid4()}`;
1219
+ return `runtime-client-${nanoid5()}`;
1022
1220
  }
1023
1221
  function readRuntimeClientIdFromTabScope(tabScope) {
1024
1222
  if (!tabScope) {
@@ -1067,7 +1265,7 @@ function getRuntimeClientId(storage, tabScope) {
1067
1265
  }
1068
1266
  }
1069
1267
  function createRuntimePageId() {
1070
- return `runtime-${nanoid4()}`;
1268
+ return `runtime-${nanoid5()}`;
1071
1269
  }
1072
1270
  function getRuntimePageIdentity(input) {
1073
1271
  return {
@@ -1087,7 +1285,7 @@ function getRuntimePageIdentity(input) {
1087
1285
  }
1088
1286
 
1089
1287
  // src/runtime/performanceHook.ts
1090
- import { nanoid as nanoid5 } from "nanoid";
1288
+ import { nanoid as nanoid6 } from "nanoid";
1091
1289
 
1092
1290
  // src/performance/summary.ts
1093
1291
  function buildPerformanceSummary(input) {
@@ -1261,7 +1459,7 @@ function createPerformanceCollector(deps) {
1261
1459
  };
1262
1460
  }
1263
1461
  function createRecordingId() {
1264
- return `performance-${nanoid5()}`;
1462
+ return `performance-${nanoid6()}`;
1265
1463
  }
1266
1464
  function startSession(state, deps, options) {
1267
1465
  const recordingId = createRecordingId();
@@ -2132,7 +2330,14 @@ function createRuntimeDevtoolsRpc(getRpc) {
2132
2330
  await bridge.manageStorage(options)
2133
2331
  );
2134
2332
  },
2135
- onStorageUpdated: () => void 0
2333
+ onStorageUpdated: () => void 0,
2334
+ inspectConsoleArg(options) {
2335
+ if (!options.event) {
2336
+ return;
2337
+ }
2338
+ getRpc().onConsoleArgInspected(options.event, inspectConsoleArg(options));
2339
+ },
2340
+ onConsoleArgInspected: () => void 0
2136
2341
  };
2137
2342
  }
2138
2343