@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.cjs CHANGED
@@ -2699,25 +2699,153 @@ 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, createRpcSafeContext(), 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 createRpcSafeContext() {
2715
+ return {
2716
+ cache: /* @__PURE__ */ new WeakMap(),
2717
+ seen: /* @__PURE__ */ new WeakSet()
2718
+ };
2719
+ }
2720
+ function toRpcSafeChildValue(value, context, arrayItem) {
2721
+ if (value === null) {
2722
+ return null;
2723
+ }
2724
+ switch (typeof value) {
2725
+ case "string":
2726
+ case "boolean":
2727
+ return value;
2728
+ case "number":
2729
+ return Number.isFinite(value) ? value : String(value);
2730
+ case "bigint":
2731
+ return value.toString();
2732
+ case "symbol":
2733
+ return toSymbolPlaceholder(value);
2734
+ case "undefined":
2735
+ case "function":
2736
+ return arrayItem ? null : void 0;
2737
+ case "object":
2738
+ return toRpcSafeObject(value, context);
2739
+ default:
2740
+ return arrayItem ? null : void 0;
2741
+ }
2742
+ }
2743
+ function toRpcSafeObject(value, context) {
2744
+ if (context.seen.has(value)) {
2745
+ return RPC_CIRCULAR_VALUE;
2746
+ }
2747
+ const cached = context.cache.get(value);
2748
+ if (cached) {
2749
+ return cached;
2750
+ }
2751
+ context.seen.add(value);
2752
+ try {
2753
+ let safeValue;
2754
+ if (value instanceof Date) {
2755
+ safeValue = toSafeDate(value);
2756
+ } else if (value instanceof Error) {
2757
+ safeValue = toSafeError(value, context);
2758
+ } else if (Array.isArray(value)) {
2759
+ safeValue = toSafeArray(value, context);
2760
+ } else {
2761
+ safeValue = toSafeRecord(value, context);
2762
+ }
2763
+ context.cache.set(value, safeValue);
2764
+ return safeValue;
2765
+ } finally {
2766
+ context.seen.delete(value);
2767
+ }
2768
+ }
2769
+ function toSafeArray(values, context) {
2770
+ return values.map((item) => toRpcSafeChildValue(item, context, true) ?? null);
2771
+ }
2772
+ function toSafeRecord(value, context) {
2773
+ const keys = getEnumerableKeys(value);
2774
+ if (!keys) {
2775
+ return RPC_UNREADABLE_VALUE;
2776
+ }
2777
+ if (keys.length === 0 && !isPlainRecord3(value)) {
2778
+ return toObjectSummary(value);
2779
+ }
2780
+ const result = {};
2781
+ keys.forEach((key) => {
2782
+ if (key === "toJSON") {
2783
+ return;
2718
2784
  }
2719
- );
2720
- return serialized;
2785
+ const field = readObjectField(value, key);
2786
+ if (!field.ok) {
2787
+ result[key] = RPC_UNREADABLE_VALUE;
2788
+ return;
2789
+ }
2790
+ const safeValue = toRpcSafeChildValue(field.value, context, false);
2791
+ if (safeValue !== void 0) {
2792
+ result[key] = safeValue;
2793
+ }
2794
+ });
2795
+ return result;
2796
+ }
2797
+ function toSafeError(error, context) {
2798
+ const result = {
2799
+ name: error.name,
2800
+ message: error.message
2801
+ };
2802
+ const stack = readObjectField(error, "stack");
2803
+ if (stack.ok && typeof stack.value === "string") {
2804
+ result.stack = stack.value;
2805
+ }
2806
+ if ("cause" in error) {
2807
+ const cause = readObjectField(error, "cause");
2808
+ result.cause = cause.ok ? toRpcSafeChildValue(cause.value, context, false) ?? null : RPC_UNREADABLE_VALUE;
2809
+ }
2810
+ return result;
2811
+ }
2812
+ function toSafeDate(value) {
2813
+ return Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
2814
+ }
2815
+ function getEnumerableKeys(value) {
2816
+ try {
2817
+ return Object.keys(value);
2818
+ } catch {
2819
+ return void 0;
2820
+ }
2821
+ }
2822
+ function readObjectField(value, key) {
2823
+ try {
2824
+ return {
2825
+ ok: true,
2826
+ value: value[key]
2827
+ };
2828
+ } catch {
2829
+ return { ok: false };
2830
+ }
2831
+ }
2832
+ function isPlainRecord3(value) {
2833
+ try {
2834
+ const prototype = Object.getPrototypeOf(value);
2835
+ return prototype === Object.prototype || prototype === null;
2836
+ } catch {
2837
+ return false;
2838
+ }
2839
+ }
2840
+ function toObjectSummary(value) {
2841
+ try {
2842
+ return Object.prototype.toString.call(value);
2843
+ } catch {
2844
+ return "[Object]";
2845
+ }
2846
+ }
2847
+ function toSymbolPlaceholder(value) {
2848
+ return value.description ? `[Symbol(${value.description})]` : "[Symbol]";
2721
2849
  }
2722
2850
 
2723
2851
  // src/cdp/cdpConsole.ts
@@ -3272,11 +3400,11 @@ var import_node_path7 = __toESM(require("path"), 1);
3272
3400
  async function updateJsonMcpClientConfig(options) {
3273
3401
  try {
3274
3402
  const config = await readJsonConfig(options.configPath);
3275
- if (!isPlainRecord3(config)) {
3403
+ if (!isPlainRecord4(config)) {
3276
3404
  warnConfigFailure(options, "config root must be a JSON object");
3277
3405
  return;
3278
3406
  }
3279
- const mcpServers = isPlainRecord3(config.mcpServers) ? config.mcpServers : {};
3407
+ const mcpServers = isPlainRecord4(config.mcpServers) ? config.mcpServers : {};
3280
3408
  if (Object.hasOwn(mcpServers, options.serverName)) {
3281
3409
  return;
3282
3410
  }
@@ -3329,7 +3457,7 @@ async function readOptionalTextFile2(filePath) {
3329
3457
  throw error;
3330
3458
  }
3331
3459
  }
3332
- function isPlainRecord3(value) {
3460
+ function isPlainRecord4(value) {
3333
3461
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
3334
3462
  }
3335
3463
  function warnConfigFailure(options, reason) {