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

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,25 @@ 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);
149
- }
150
145
  function safeStringify(value) {
151
146
  if (typeof value === "string") {
152
147
  return value;
153
148
  }
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
- };
162
- }
163
- function toRpcSafeChildValue(value, context, arrayItem) {
164
- if (value === null) {
165
- return null;
166
- }
167
- switch (typeof value) {
168
- case "string":
169
- case "boolean":
170
- return value;
171
- case "number":
172
- return Number.isFinite(value) ? value : String(value);
173
- case "bigint":
174
- return value.toString();
175
- case "symbol":
176
- return toSymbolPlaceholder(value);
177
- case "undefined":
178
- case "function":
179
- return arrayItem ? null : void 0;
180
- case "object":
181
- return toRpcSafeObject(value, context);
182
- default:
183
- return arrayItem ? null : void 0;
184
- }
185
- }
186
- function toRpcSafeObject(value, context) {
187
- if (context.seen.has(value)) {
188
- return RPC_CIRCULAR_VALUE;
189
- }
190
- const cached = context.cache.get(value);
191
- if (cached) {
192
- return cached;
193
- }
194
- 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);
210
- }
211
- }
212
- function toSafeArray(values, context) {
213
- return values.map((item) => toRpcSafeChildValue(item, context, true) ?? null);
214
- }
215
- function toSafeRecord(value, context) {
216
- const keys = getEnumerableKeys(value);
217
- if (!keys) {
218
- return RPC_UNREADABLE_VALUE;
219
- }
220
- if (keys.length === 0 && !isPlainRecord(value)) {
221
- return toObjectSummary(value);
222
- }
223
- 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;
149
+ const seen = /* @__PURE__ */ new WeakSet();
150
+ const serialized = JSON.stringify(
151
+ value,
152
+ (_key, current) => {
153
+ if (typeof current !== "object" || current === null) {
154
+ return current;
155
+ }
156
+ if (seen.has(current)) {
157
+ return "[Circular]";
158
+ }
159
+ seen.add(current);
160
+ return current;
236
161
  }
237
- });
238
- return result;
239
- }
240
- function toSafeError(error, context) {
241
- const result = {
242
- name: error.name,
243
- message: error.message
244
- };
245
- const stack = readObjectField(error, "stack");
246
- if (stack.ok && typeof stack.value === "string") {
247
- result.stack = stack.value;
248
- }
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;
252
- }
253
- return result;
254
- }
255
- function toSafeDate(value) {
256
- return Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
257
- }
258
- function getEnumerableKeys(value) {
259
- try {
260
- return Object.keys(value);
261
- } catch {
262
- return void 0;
263
- }
264
- }
265
- function readObjectField(value, key) {
266
- try {
267
- return {
268
- ok: true,
269
- value: value[key]
270
- };
271
- } catch {
272
- return { ok: false };
273
- }
274
- }
275
- function isPlainRecord(value) {
276
- try {
277
- const prototype = Object.getPrototypeOf(value);
278
- return prototype === Object.prototype || prototype === null;
279
- } catch {
280
- return false;
281
- }
282
- }
283
- function toObjectSummary(value) {
284
- try {
285
- return Object.prototype.toString.call(value);
286
- } catch {
287
- return "[Object]";
288
- }
289
- }
290
- function toSymbolPlaceholder(value) {
291
- return value.description ? `[Symbol(${value.description})]` : "[Symbol]";
162
+ );
163
+ return serialized;
292
164
  }
293
165
 
294
166
  // src/runtime/consoleHook.ts
@@ -301,14 +173,13 @@ function installConsoleHook(options) {
301
173
  debug: console.debug
302
174
  };
303
175
  const emit = (level, args) => {
304
- const serializedArgs = serializeConsoleArgs(args);
305
176
  options.send({
306
177
  id: (0, import_nanoid.nanoid)(),
307
178
  pageId: options.pageId,
308
179
  source: "hook",
309
180
  level,
310
- message: serializedArgs.join(" "),
311
- args: serializedArgs,
181
+ message: args.map((arg) => safeStringify(arg)).join(" "),
182
+ args,
312
183
  timestamp: Date.now()
313
184
  });
314
185
  };
@@ -335,9 +206,6 @@ function installConsoleHook(options) {
335
206
  window.removeEventListener("error", onError);
336
207
  };
337
208
  }
338
- function serializeConsoleArgs(args) {
339
- return args.map((arg) => safeStringify(arg));
340
- }
341
209
 
342
210
  // src/runtime/elementRegistry.ts
343
211
  var import_nanoid2 = require("nanoid");
@@ -2171,15 +2039,6 @@ function installVueBridge(hot) {
2171
2039
  );
2172
2040
  rpcRef.current = rpc;
2173
2041
  }
2174
- function toVueRpcPayload(value) {
2175
- return toRpcSafeValue(value);
2176
- }
2177
- function toVueRpcJsonPayload(value) {
2178
- return JSON.stringify(toRpcSafeValue(value) ?? null);
2179
- }
2180
- function toVueRpcPrettyJsonPayload(value) {
2181
- return JSON.stringify(toRpcSafeValue(value), null, 2);
2182
- }
2183
2042
  function createClientVueRuntimeRpc(getRpc) {
2184
2043
  return {
2185
2044
  ...createRuntimeDevtoolsRpc(getRpc),
@@ -2188,10 +2047,7 @@ function createClientVueRuntimeRpc(getRpc) {
2188
2047
  inspectorId: COMPONENTS_INSPECTOR_ID,
2189
2048
  filter: query.componentName ?? ""
2190
2049
  });
2191
- getRpc().onInspectorTreeUpdated(
2192
- query.event,
2193
- toVueRpcPayload(inspectorTree[0])
2194
- );
2050
+ getRpc().onInspectorTreeUpdated(query.event, inspectorTree[0]);
2195
2051
  },
2196
2052
  onInspectorTreeUpdated: () => void 0,
2197
2053
  async getInspectorState(query) {
@@ -2199,7 +2055,7 @@ function createClientVueRuntimeRpc(getRpc) {
2199
2055
  if (!targetNode) {
2200
2056
  getRpc().onInspectorStateUpdated(
2201
2057
  query.event,
2202
- toVueRpcPayload(createMissingComponentError(query.componentName))
2058
+ createMissingComponentError(query.componentName)
2203
2059
  );
2204
2060
  return;
2205
2061
  }
@@ -2207,10 +2063,7 @@ function createClientVueRuntimeRpc(getRpc) {
2207
2063
  inspectorId: COMPONENTS_INSPECTOR_ID,
2208
2064
  nodeId: targetNode.id
2209
2065
  });
2210
- getRpc().onInspectorStateUpdated(
2211
- query.event,
2212
- toVueRpcJsonPayload(inspectorState)
2213
- );
2066
+ getRpc().onInspectorStateUpdated(query.event, (0, import_devtools_kit.stringify)(inspectorState));
2214
2067
  },
2215
2068
  onInspectorStateUpdated: () => void 0,
2216
2069
  async editComponentState(query) {
@@ -2247,7 +2100,7 @@ function createClientVueRuntimeRpc(getRpc) {
2247
2100
  getRouterInfo(query) {
2248
2101
  getRpc().onRouterInfoUpdated(
2249
2102
  query.event,
2250
- toVueRpcPrettyJsonPayload(import_devtools_kit.devtoolsRouterInfo)
2103
+ JSON.stringify(import_devtools_kit.devtoolsRouterInfo, null, 2)
2251
2104
  );
2252
2105
  },
2253
2106
  onRouterInfoUpdated: () => void 0,
@@ -2258,7 +2111,7 @@ function createClientVueRuntimeRpc(getRpc) {
2258
2111
  filter: ""
2259
2112
  })
2260
2113
  );
2261
- getRpc().onPiniaTreeUpdated(query.event, toVueRpcPayload(inspectorTree));
2114
+ getRpc().onPiniaTreeUpdated(query.event, inspectorTree);
2262
2115
  },
2263
2116
  onPiniaTreeUpdated: () => void 0,
2264
2117
  async getPiniaState(query) {
@@ -2273,7 +2126,7 @@ function createClientVueRuntimeRpc(getRpc) {
2273
2126
  }
2274
2127
  return import_devtools_kit.devtools.ctx.api.getInspectorState(payload);
2275
2128
  });
2276
- getRpc().onPiniaInfoUpdated(query.event, toVueRpcJsonPayload(result));
2129
+ getRpc().onPiniaInfoUpdated(query.event, (0, import_devtools_kit.stringify)(result));
2277
2130
  },
2278
2131
  onPiniaInfoUpdated: () => void 0,
2279
2132
  async recordPerformance(query) {
@@ -2281,7 +2134,7 @@ function createClientVueRuntimeRpc(getRpc) {
2281
2134
  if (!collector) {
2282
2135
  getRpc().onPerformanceRecorded(
2283
2136
  query.event,
2284
- toVueRpcPayload(createPerformanceUnavailableError())
2137
+ createPerformanceUnavailableError()
2285
2138
  );
2286
2139
  return;
2287
2140
  }
@@ -2291,11 +2144,11 @@ function createClientVueRuntimeRpc(getRpc) {
2291
2144
  includeMemory: query.includeMemory,
2292
2145
  includeStacks: query.includeStacks
2293
2146
  });
2294
- getRpc().onPerformanceRecorded(query.event, toVueRpcPayload(report));
2147
+ getRpc().onPerformanceRecorded(query.event, report);
2295
2148
  } catch (error) {
2296
2149
  getRpc().onPerformanceRecorded(
2297
2150
  query.event,
2298
- toVueRpcPayload(createPerformanceError(error))
2151
+ createPerformanceError(error)
2299
2152
  );
2300
2153
  }
2301
2154
  },
@@ -2305,7 +2158,7 @@ function createClientVueRuntimeRpc(getRpc) {
2305
2158
  if (!collector) {
2306
2159
  getRpc().onPerformanceRecordingStarted(
2307
2160
  query.event,
2308
- toVueRpcPayload(createPerformanceUnavailableError())
2161
+ createPerformanceUnavailableError()
2309
2162
  );
2310
2163
  return;
2311
2164
  }
@@ -2314,19 +2167,16 @@ function createClientVueRuntimeRpc(getRpc) {
2314
2167
  includeMemory: query.includeMemory,
2315
2168
  includeStacks: query.includeStacks
2316
2169
  });
2317
- getRpc().onPerformanceRecordingStarted(
2318
- query.event,
2319
- toVueRpcPayload({
2320
- ok: true,
2321
- recordingId,
2322
- startedAt: Date.now(),
2323
- source: "hook"
2324
- })
2325
- );
2170
+ getRpc().onPerformanceRecordingStarted(query.event, {
2171
+ ok: true,
2172
+ recordingId,
2173
+ startedAt: Date.now(),
2174
+ source: "hook"
2175
+ });
2326
2176
  } catch (error) {
2327
2177
  getRpc().onPerformanceRecordingStarted(
2328
2178
  query.event,
2329
- toVueRpcPayload(createPerformanceError(error))
2179
+ createPerformanceError(error)
2330
2180
  );
2331
2181
  }
2332
2182
  },
@@ -2336,20 +2186,17 @@ function createClientVueRuntimeRpc(getRpc) {
2336
2186
  if (!collector) {
2337
2187
  getRpc().onPerformanceRecordingStopped(
2338
2188
  query.event,
2339
- toVueRpcPayload(createPerformanceUnavailableError())
2189
+ createPerformanceUnavailableError()
2340
2190
  );
2341
2191
  return;
2342
2192
  }
2343
2193
  try {
2344
2194
  const report = collector.stop(query.recordingId);
2345
- getRpc().onPerformanceRecordingStopped(
2346
- query.event,
2347
- toVueRpcPayload(report)
2348
- );
2195
+ getRpc().onPerformanceRecordingStopped(query.event, report);
2349
2196
  } catch (error) {
2350
2197
  getRpc().onPerformanceRecordingStopped(
2351
2198
  query.event,
2352
- toVueRpcPayload(createPerformanceError(error))
2199
+ createPerformanceError(error)
2353
2200
  );
2354
2201
  }
2355
2202
  },