@xiaou66/vite-plugin-vue-mcp-next 1.3.1 → 1.3.3

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.js CHANGED
@@ -2662,25 +2662,153 @@ function createServerVueRuntimeRpc(ctx) {
2662
2662
  import { nanoid as nanoid4 } from "nanoid";
2663
2663
 
2664
2664
  // src/shared/serialization.ts
2665
+ var RPC_CIRCULAR_VALUE = "[Circular]";
2666
+ var RPC_UNREADABLE_VALUE = "[Unreadable]";
2667
+ function toRpcSafeValue(value) {
2668
+ return toRpcSafeChildValue(value, createRpcSafeContext(), false);
2669
+ }
2665
2670
  function safeStringify(value) {
2666
2671
  if (typeof value === "string") {
2667
2672
  return value;
2668
2673
  }
2669
- const seen = /* @__PURE__ */ new WeakSet();
2670
- const serialized = JSON.stringify(
2671
- value,
2672
- (_key, current) => {
2673
- if (typeof current !== "object" || current === null) {
2674
- return current;
2675
- }
2676
- if (seen.has(current)) {
2677
- return "[Circular]";
2678
- }
2679
- seen.add(current);
2680
- return current;
2674
+ const safeValue = toRpcSafeValue(value);
2675
+ return safeValue === void 0 ? "undefined" : JSON.stringify(safeValue);
2676
+ }
2677
+ function createRpcSafeContext() {
2678
+ return {
2679
+ cache: /* @__PURE__ */ new WeakMap(),
2680
+ seen: /* @__PURE__ */ new WeakSet()
2681
+ };
2682
+ }
2683
+ function toRpcSafeChildValue(value, context, arrayItem) {
2684
+ if (value === null) {
2685
+ return null;
2686
+ }
2687
+ switch (typeof value) {
2688
+ case "string":
2689
+ case "boolean":
2690
+ return value;
2691
+ case "number":
2692
+ return Number.isFinite(value) ? value : String(value);
2693
+ case "bigint":
2694
+ return value.toString();
2695
+ case "symbol":
2696
+ return toSymbolPlaceholder(value);
2697
+ case "undefined":
2698
+ case "function":
2699
+ return arrayItem ? null : void 0;
2700
+ case "object":
2701
+ return toRpcSafeObject(value, context);
2702
+ default:
2703
+ return arrayItem ? null : void 0;
2704
+ }
2705
+ }
2706
+ function toRpcSafeObject(value, context) {
2707
+ if (context.seen.has(value)) {
2708
+ return RPC_CIRCULAR_VALUE;
2709
+ }
2710
+ const cached = context.cache.get(value);
2711
+ if (cached) {
2712
+ return cached;
2713
+ }
2714
+ context.seen.add(value);
2715
+ try {
2716
+ let safeValue;
2717
+ if (value instanceof Date) {
2718
+ safeValue = toSafeDate(value);
2719
+ } else if (value instanceof Error) {
2720
+ safeValue = toSafeError(value, context);
2721
+ } else if (Array.isArray(value)) {
2722
+ safeValue = toSafeArray(value, context);
2723
+ } else {
2724
+ safeValue = toSafeRecord(value, context);
2725
+ }
2726
+ context.cache.set(value, safeValue);
2727
+ return safeValue;
2728
+ } finally {
2729
+ context.seen.delete(value);
2730
+ }
2731
+ }
2732
+ function toSafeArray(values, context) {
2733
+ return values.map((item) => toRpcSafeChildValue(item, context, true) ?? null);
2734
+ }
2735
+ function toSafeRecord(value, context) {
2736
+ const keys = getEnumerableKeys(value);
2737
+ if (!keys) {
2738
+ return RPC_UNREADABLE_VALUE;
2739
+ }
2740
+ if (keys.length === 0 && !isPlainRecord3(value)) {
2741
+ return toObjectSummary(value);
2742
+ }
2743
+ const result = {};
2744
+ keys.forEach((key) => {
2745
+ if (key === "toJSON") {
2746
+ return;
2681
2747
  }
2682
- );
2683
- return serialized;
2748
+ const field = readObjectField(value, key);
2749
+ if (!field.ok) {
2750
+ result[key] = RPC_UNREADABLE_VALUE;
2751
+ return;
2752
+ }
2753
+ const safeValue = toRpcSafeChildValue(field.value, context, false);
2754
+ if (safeValue !== void 0) {
2755
+ result[key] = safeValue;
2756
+ }
2757
+ });
2758
+ return result;
2759
+ }
2760
+ function toSafeError(error, context) {
2761
+ const result = {
2762
+ name: error.name,
2763
+ message: error.message
2764
+ };
2765
+ const stack = readObjectField(error, "stack");
2766
+ if (stack.ok && typeof stack.value === "string") {
2767
+ result.stack = stack.value;
2768
+ }
2769
+ if ("cause" in error) {
2770
+ const cause = readObjectField(error, "cause");
2771
+ result.cause = cause.ok ? toRpcSafeChildValue(cause.value, context, false) ?? null : RPC_UNREADABLE_VALUE;
2772
+ }
2773
+ return result;
2774
+ }
2775
+ function toSafeDate(value) {
2776
+ return Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
2777
+ }
2778
+ function getEnumerableKeys(value) {
2779
+ try {
2780
+ return Object.keys(value);
2781
+ } catch {
2782
+ return void 0;
2783
+ }
2784
+ }
2785
+ function readObjectField(value, key) {
2786
+ try {
2787
+ return {
2788
+ ok: true,
2789
+ value: value[key]
2790
+ };
2791
+ } catch {
2792
+ return { ok: false };
2793
+ }
2794
+ }
2795
+ function isPlainRecord3(value) {
2796
+ try {
2797
+ const prototype = Object.getPrototypeOf(value);
2798
+ return prototype === Object.prototype || prototype === null;
2799
+ } catch {
2800
+ return false;
2801
+ }
2802
+ }
2803
+ function toObjectSummary(value) {
2804
+ try {
2805
+ return Object.prototype.toString.call(value);
2806
+ } catch {
2807
+ return "[Object]";
2808
+ }
2809
+ }
2810
+ function toSymbolPlaceholder(value) {
2811
+ return value.description ? `[Symbol(${value.description})]` : "[Symbol]";
2684
2812
  }
2685
2813
 
2686
2814
  // src/cdp/cdpConsole.ts
@@ -3235,11 +3363,11 @@ import path4 from "path";
3235
3363
  async function updateJsonMcpClientConfig(options) {
3236
3364
  try {
3237
3365
  const config = await readJsonConfig(options.configPath);
3238
- if (!isPlainRecord3(config)) {
3366
+ if (!isPlainRecord4(config)) {
3239
3367
  warnConfigFailure(options, "config root must be a JSON object");
3240
3368
  return;
3241
3369
  }
3242
- const mcpServers = isPlainRecord3(config.mcpServers) ? config.mcpServers : {};
3370
+ const mcpServers = isPlainRecord4(config.mcpServers) ? config.mcpServers : {};
3243
3371
  if (Object.hasOwn(mcpServers, options.serverName)) {
3244
3372
  return;
3245
3373
  }
@@ -3292,7 +3420,7 @@ async function readOptionalTextFile2(filePath) {
3292
3420
  throw error;
3293
3421
  }
3294
3422
  }
3295
- function isPlainRecord3(value) {
3423
+ function isPlainRecord4(value) {
3296
3424
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
3297
3425
  }
3298
3426
  function warnConfigFailure(options, reason) {