@xiaou66/vite-plugin-vue-mcp-next 1.3.1 → 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.
@@ -142,25 +142,141 @@ 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, /* @__PURE__ */ new WeakSet(), false);
149
+ }
145
150
  function safeStringify(value) {
146
151
  if (typeof value === "string") {
147
152
  return value;
148
153
  }
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;
154
+ const safeValue = toRpcSafeValue(value);
155
+ return safeValue === void 0 ? "undefined" : JSON.stringify(safeValue);
156
+ }
157
+ function toRpcSafeChildValue(value, seen, arrayItem) {
158
+ if (value === null) {
159
+ return null;
160
+ }
161
+ switch (typeof value) {
162
+ case "string":
163
+ case "boolean":
164
+ return value;
165
+ case "number":
166
+ return Number.isFinite(value) ? value : String(value);
167
+ case "bigint":
168
+ return value.toString();
169
+ case "symbol":
170
+ return toSymbolPlaceholder(value);
171
+ case "undefined":
172
+ case "function":
173
+ return arrayItem ? null : void 0;
174
+ case "object":
175
+ return toRpcSafeObject(value, seen);
176
+ default:
177
+ return arrayItem ? null : void 0;
178
+ }
179
+ }
180
+ function toRpcSafeObject(value, seen) {
181
+ if (seen.has(value)) {
182
+ return RPC_CIRCULAR_VALUE;
183
+ }
184
+ seen.add(value);
185
+ try {
186
+ if (value instanceof Date) {
187
+ return toSafeDate(value);
161
188
  }
162
- );
163
- return serialized;
189
+ if (value instanceof Error) {
190
+ return toSafeError(value, seen);
191
+ }
192
+ if (Array.isArray(value)) {
193
+ return toSafeArray(value, seen);
194
+ }
195
+ return toSafeRecord(value, seen);
196
+ } finally {
197
+ seen.delete(value);
198
+ }
199
+ }
200
+ function toSafeArray(values, seen) {
201
+ return values.map((item) => toRpcSafeChildValue(item, seen, true) ?? null);
202
+ }
203
+ function toSafeRecord(value, seen) {
204
+ const keys = getEnumerableKeys(value);
205
+ if (!keys) {
206
+ return RPC_UNREADABLE_VALUE;
207
+ }
208
+ if (keys.length === 0 && !isPlainRecord(value)) {
209
+ return toObjectSummary(value);
210
+ }
211
+ const result = {};
212
+ keys.forEach((key) => {
213
+ if (key === "toJSON") {
214
+ return;
215
+ }
216
+ const field = readObjectField(value, key);
217
+ if (!field.ok) {
218
+ result[key] = RPC_UNREADABLE_VALUE;
219
+ return;
220
+ }
221
+ const safeValue = toRpcSafeChildValue(field.value, seen, false);
222
+ if (safeValue !== void 0) {
223
+ result[key] = safeValue;
224
+ }
225
+ });
226
+ return result;
227
+ }
228
+ function toSafeError(error, seen) {
229
+ const result = {
230
+ name: error.name,
231
+ message: error.message
232
+ };
233
+ const stack = readObjectField(error, "stack");
234
+ if (stack.ok && typeof stack.value === "string") {
235
+ result.stack = stack.value;
236
+ }
237
+ if ("cause" in error) {
238
+ const cause = readObjectField(error, "cause");
239
+ result.cause = cause.ok ? toRpcSafeChildValue(cause.value, seen, false) ?? null : RPC_UNREADABLE_VALUE;
240
+ }
241
+ return result;
242
+ }
243
+ function toSafeDate(value) {
244
+ return Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
245
+ }
246
+ function getEnumerableKeys(value) {
247
+ try {
248
+ return Object.keys(value);
249
+ } catch {
250
+ return void 0;
251
+ }
252
+ }
253
+ function readObjectField(value, key) {
254
+ try {
255
+ return {
256
+ ok: true,
257
+ value: value[key]
258
+ };
259
+ } catch {
260
+ return { ok: false };
261
+ }
262
+ }
263
+ function isPlainRecord(value) {
264
+ try {
265
+ const prototype = Object.getPrototypeOf(value);
266
+ return prototype === Object.prototype || prototype === null;
267
+ } catch {
268
+ return false;
269
+ }
270
+ }
271
+ function toObjectSummary(value) {
272
+ try {
273
+ return Object.prototype.toString.call(value);
274
+ } catch {
275
+ return "[Object]";
276
+ }
277
+ }
278
+ function toSymbolPlaceholder(value) {
279
+ return value.description ? `[Symbol(${value.description})]` : "[Symbol]";
164
280
  }
165
281
 
166
282
  // src/runtime/consoleHook.ts
@@ -2043,6 +2159,15 @@ function installVueBridge(hot) {
2043
2159
  );
2044
2160
  rpcRef.current = rpc;
2045
2161
  }
2162
+ function toVueRpcPayload(value) {
2163
+ return toRpcSafeValue(value);
2164
+ }
2165
+ function toVueRpcJsonPayload(value) {
2166
+ return JSON.stringify(toRpcSafeValue(value) ?? null);
2167
+ }
2168
+ function toVueRpcPrettyJsonPayload(value) {
2169
+ return JSON.stringify(toRpcSafeValue(value), null, 2);
2170
+ }
2046
2171
  function createClientVueRuntimeRpc(getRpc) {
2047
2172
  return {
2048
2173
  ...createRuntimeDevtoolsRpc(getRpc),
@@ -2051,7 +2176,10 @@ function createClientVueRuntimeRpc(getRpc) {
2051
2176
  inspectorId: COMPONENTS_INSPECTOR_ID,
2052
2177
  filter: query.componentName ?? ""
2053
2178
  });
2054
- getRpc().onInspectorTreeUpdated(query.event, inspectorTree[0]);
2179
+ getRpc().onInspectorTreeUpdated(
2180
+ query.event,
2181
+ toVueRpcPayload(inspectorTree[0])
2182
+ );
2055
2183
  },
2056
2184
  onInspectorTreeUpdated: () => void 0,
2057
2185
  async getInspectorState(query) {
@@ -2059,7 +2187,7 @@ function createClientVueRuntimeRpc(getRpc) {
2059
2187
  if (!targetNode) {
2060
2188
  getRpc().onInspectorStateUpdated(
2061
2189
  query.event,
2062
- createMissingComponentError(query.componentName)
2190
+ toVueRpcPayload(createMissingComponentError(query.componentName))
2063
2191
  );
2064
2192
  return;
2065
2193
  }
@@ -2067,7 +2195,10 @@ function createClientVueRuntimeRpc(getRpc) {
2067
2195
  inspectorId: COMPONENTS_INSPECTOR_ID,
2068
2196
  nodeId: targetNode.id
2069
2197
  });
2070
- getRpc().onInspectorStateUpdated(query.event, (0, import_devtools_kit.stringify)(inspectorState));
2198
+ getRpc().onInspectorStateUpdated(
2199
+ query.event,
2200
+ toVueRpcJsonPayload(inspectorState)
2201
+ );
2071
2202
  },
2072
2203
  onInspectorStateUpdated: () => void 0,
2073
2204
  async editComponentState(query) {
@@ -2104,7 +2235,7 @@ function createClientVueRuntimeRpc(getRpc) {
2104
2235
  getRouterInfo(query) {
2105
2236
  getRpc().onRouterInfoUpdated(
2106
2237
  query.event,
2107
- JSON.stringify(import_devtools_kit.devtoolsRouterInfo, null, 2)
2238
+ toVueRpcPrettyJsonPayload(import_devtools_kit.devtoolsRouterInfo)
2108
2239
  );
2109
2240
  },
2110
2241
  onRouterInfoUpdated: () => void 0,
@@ -2115,7 +2246,7 @@ function createClientVueRuntimeRpc(getRpc) {
2115
2246
  filter: ""
2116
2247
  })
2117
2248
  );
2118
- getRpc().onPiniaTreeUpdated(query.event, inspectorTree);
2249
+ getRpc().onPiniaTreeUpdated(query.event, toVueRpcPayload(inspectorTree));
2119
2250
  },
2120
2251
  onPiniaTreeUpdated: () => void 0,
2121
2252
  async getPiniaState(query) {
@@ -2130,7 +2261,7 @@ function createClientVueRuntimeRpc(getRpc) {
2130
2261
  }
2131
2262
  return import_devtools_kit.devtools.ctx.api.getInspectorState(payload);
2132
2263
  });
2133
- getRpc().onPiniaInfoUpdated(query.event, (0, import_devtools_kit.stringify)(result));
2264
+ getRpc().onPiniaInfoUpdated(query.event, toVueRpcJsonPayload(result));
2134
2265
  },
2135
2266
  onPiniaInfoUpdated: () => void 0,
2136
2267
  async recordPerformance(query) {
@@ -2138,7 +2269,7 @@ function createClientVueRuntimeRpc(getRpc) {
2138
2269
  if (!collector) {
2139
2270
  getRpc().onPerformanceRecorded(
2140
2271
  query.event,
2141
- createPerformanceUnavailableError()
2272
+ toVueRpcPayload(createPerformanceUnavailableError())
2142
2273
  );
2143
2274
  return;
2144
2275
  }
@@ -2148,11 +2279,11 @@ function createClientVueRuntimeRpc(getRpc) {
2148
2279
  includeMemory: query.includeMemory,
2149
2280
  includeStacks: query.includeStacks
2150
2281
  });
2151
- getRpc().onPerformanceRecorded(query.event, report);
2282
+ getRpc().onPerformanceRecorded(query.event, toVueRpcPayload(report));
2152
2283
  } catch (error) {
2153
2284
  getRpc().onPerformanceRecorded(
2154
2285
  query.event,
2155
- createPerformanceError(error)
2286
+ toVueRpcPayload(createPerformanceError(error))
2156
2287
  );
2157
2288
  }
2158
2289
  },
@@ -2162,7 +2293,7 @@ function createClientVueRuntimeRpc(getRpc) {
2162
2293
  if (!collector) {
2163
2294
  getRpc().onPerformanceRecordingStarted(
2164
2295
  query.event,
2165
- createPerformanceUnavailableError()
2296
+ toVueRpcPayload(createPerformanceUnavailableError())
2166
2297
  );
2167
2298
  return;
2168
2299
  }
@@ -2171,16 +2302,19 @@ function createClientVueRuntimeRpc(getRpc) {
2171
2302
  includeMemory: query.includeMemory,
2172
2303
  includeStacks: query.includeStacks
2173
2304
  });
2174
- getRpc().onPerformanceRecordingStarted(query.event, {
2175
- ok: true,
2176
- recordingId,
2177
- startedAt: Date.now(),
2178
- source: "hook"
2179
- });
2305
+ getRpc().onPerformanceRecordingStarted(
2306
+ query.event,
2307
+ toVueRpcPayload({
2308
+ ok: true,
2309
+ recordingId,
2310
+ startedAt: Date.now(),
2311
+ source: "hook"
2312
+ })
2313
+ );
2180
2314
  } catch (error) {
2181
2315
  getRpc().onPerformanceRecordingStarted(
2182
2316
  query.event,
2183
- createPerformanceError(error)
2317
+ toVueRpcPayload(createPerformanceError(error))
2184
2318
  );
2185
2319
  }
2186
2320
  },
@@ -2190,17 +2324,20 @@ function createClientVueRuntimeRpc(getRpc) {
2190
2324
  if (!collector) {
2191
2325
  getRpc().onPerformanceRecordingStopped(
2192
2326
  query.event,
2193
- createPerformanceUnavailableError()
2327
+ toVueRpcPayload(createPerformanceUnavailableError())
2194
2328
  );
2195
2329
  return;
2196
2330
  }
2197
2331
  try {
2198
2332
  const report = collector.stop(query.recordingId);
2199
- getRpc().onPerformanceRecordingStopped(query.event, report);
2333
+ getRpc().onPerformanceRecordingStopped(
2334
+ query.event,
2335
+ toVueRpcPayload(report)
2336
+ );
2200
2337
  } catch (error) {
2201
2338
  getRpc().onPerformanceRecordingStopped(
2202
2339
  query.event,
2203
- createPerformanceError(error)
2340
+ toVueRpcPayload(createPerformanceError(error))
2204
2341
  );
2205
2342
  }
2206
2343
  },