@xiaou66/vite-plugin-vue-mcp-next 1.3.0 → 1.3.2

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 CHANGED
@@ -528,7 +528,7 @@ interface ConsoleRecord {
528
528
  source: 'cdp' | 'hook'
529
529
  level: 'log' | 'info' | 'warn' | 'error' | 'debug'
530
530
  message: string
531
- args?: unknown[]
531
+ args?: string[]
532
532
  stack?: string
533
533
  timestamp: number
534
534
  }
package/dist/index.cjs CHANGED
@@ -2699,25 +2699,141 @@ function createServerVueRuntimeRpc(ctx) {
2699
2699
  var import_nanoid4 = require("nanoid");
2700
2700
 
2701
2701
  // src/shared/serialization.ts
2702
+ var RPC_CIRCULAR_VALUE = "[Circular]";
2703
+ var RPC_UNREADABLE_VALUE = "[Unreadable]";
2704
+ function toRpcSafeValue(value) {
2705
+ return toRpcSafeChildValue(value, /* @__PURE__ */ new WeakSet(), false);
2706
+ }
2702
2707
  function safeStringify(value) {
2703
2708
  if (typeof value === "string") {
2704
2709
  return value;
2705
2710
  }
2706
- const seen = /* @__PURE__ */ new WeakSet();
2707
- const serialized = JSON.stringify(
2708
- value,
2709
- (_key, current) => {
2710
- if (typeof current !== "object" || current === null) {
2711
- return current;
2712
- }
2713
- if (seen.has(current)) {
2714
- return "[Circular]";
2715
- }
2716
- seen.add(current);
2717
- return current;
2711
+ const safeValue = toRpcSafeValue(value);
2712
+ return safeValue === void 0 ? "undefined" : JSON.stringify(safeValue);
2713
+ }
2714
+ function toRpcSafeChildValue(value, seen, arrayItem) {
2715
+ if (value === null) {
2716
+ return null;
2717
+ }
2718
+ switch (typeof value) {
2719
+ case "string":
2720
+ case "boolean":
2721
+ return value;
2722
+ case "number":
2723
+ return Number.isFinite(value) ? value : String(value);
2724
+ case "bigint":
2725
+ return value.toString();
2726
+ case "symbol":
2727
+ return toSymbolPlaceholder(value);
2728
+ case "undefined":
2729
+ case "function":
2730
+ return arrayItem ? null : void 0;
2731
+ case "object":
2732
+ return toRpcSafeObject(value, seen);
2733
+ default:
2734
+ return arrayItem ? null : void 0;
2735
+ }
2736
+ }
2737
+ function toRpcSafeObject(value, seen) {
2738
+ if (seen.has(value)) {
2739
+ return RPC_CIRCULAR_VALUE;
2740
+ }
2741
+ seen.add(value);
2742
+ try {
2743
+ if (value instanceof Date) {
2744
+ return toSafeDate(value);
2718
2745
  }
2719
- );
2720
- return serialized;
2746
+ if (value instanceof Error) {
2747
+ return toSafeError(value, seen);
2748
+ }
2749
+ if (Array.isArray(value)) {
2750
+ return toSafeArray(value, seen);
2751
+ }
2752
+ return toSafeRecord(value, seen);
2753
+ } finally {
2754
+ seen.delete(value);
2755
+ }
2756
+ }
2757
+ function toSafeArray(values, seen) {
2758
+ return values.map((item) => toRpcSafeChildValue(item, seen, true) ?? null);
2759
+ }
2760
+ function toSafeRecord(value, seen) {
2761
+ const keys = getEnumerableKeys(value);
2762
+ if (!keys) {
2763
+ return RPC_UNREADABLE_VALUE;
2764
+ }
2765
+ if (keys.length === 0 && !isPlainRecord3(value)) {
2766
+ return toObjectSummary(value);
2767
+ }
2768
+ const result = {};
2769
+ keys.forEach((key) => {
2770
+ if (key === "toJSON") {
2771
+ return;
2772
+ }
2773
+ const field = readObjectField(value, key);
2774
+ if (!field.ok) {
2775
+ result[key] = RPC_UNREADABLE_VALUE;
2776
+ return;
2777
+ }
2778
+ const safeValue = toRpcSafeChildValue(field.value, seen, false);
2779
+ if (safeValue !== void 0) {
2780
+ result[key] = safeValue;
2781
+ }
2782
+ });
2783
+ return result;
2784
+ }
2785
+ function toSafeError(error, seen) {
2786
+ const result = {
2787
+ name: error.name,
2788
+ message: error.message
2789
+ };
2790
+ const stack = readObjectField(error, "stack");
2791
+ if (stack.ok && typeof stack.value === "string") {
2792
+ result.stack = stack.value;
2793
+ }
2794
+ if ("cause" in error) {
2795
+ const cause = readObjectField(error, "cause");
2796
+ result.cause = cause.ok ? toRpcSafeChildValue(cause.value, seen, false) ?? null : RPC_UNREADABLE_VALUE;
2797
+ }
2798
+ return result;
2799
+ }
2800
+ function toSafeDate(value) {
2801
+ return Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
2802
+ }
2803
+ function getEnumerableKeys(value) {
2804
+ try {
2805
+ return Object.keys(value);
2806
+ } catch {
2807
+ return void 0;
2808
+ }
2809
+ }
2810
+ function readObjectField(value, key) {
2811
+ try {
2812
+ return {
2813
+ ok: true,
2814
+ value: value[key]
2815
+ };
2816
+ } catch {
2817
+ return { ok: false };
2818
+ }
2819
+ }
2820
+ function isPlainRecord3(value) {
2821
+ try {
2822
+ const prototype = Object.getPrototypeOf(value);
2823
+ return prototype === Object.prototype || prototype === null;
2824
+ } catch {
2825
+ return false;
2826
+ }
2827
+ }
2828
+ function toObjectSummary(value) {
2829
+ try {
2830
+ return Object.prototype.toString.call(value);
2831
+ } catch {
2832
+ return "[Object]";
2833
+ }
2834
+ }
2835
+ function toSymbolPlaceholder(value) {
2836
+ return value.description ? `[Symbol(${value.description})]` : "[Symbol]";
2721
2837
  }
2722
2838
 
2723
2839
  // src/cdp/cdpConsole.ts
@@ -3272,11 +3388,11 @@ var import_node_path7 = __toESM(require("path"), 1);
3272
3388
  async function updateJsonMcpClientConfig(options) {
3273
3389
  try {
3274
3390
  const config = await readJsonConfig(options.configPath);
3275
- if (!isPlainRecord3(config)) {
3391
+ if (!isPlainRecord4(config)) {
3276
3392
  warnConfigFailure(options, "config root must be a JSON object");
3277
3393
  return;
3278
3394
  }
3279
- const mcpServers = isPlainRecord3(config.mcpServers) ? config.mcpServers : {};
3395
+ const mcpServers = isPlainRecord4(config.mcpServers) ? config.mcpServers : {};
3280
3396
  if (Object.hasOwn(mcpServers, options.serverName)) {
3281
3397
  return;
3282
3398
  }
@@ -3329,7 +3445,7 @@ async function readOptionalTextFile2(filePath) {
3329
3445
  throw error;
3330
3446
  }
3331
3447
  }
3332
- function isPlainRecord3(value) {
3448
+ function isPlainRecord4(value) {
3333
3449
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
3334
3450
  }
3335
3451
  function warnConfigFailure(options, reason) {