@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.
@@ -1,4 +1,4 @@
1
- import { h as RuntimeClientOptions } from '../types-BKXdHkwk.cjs';
1
+ import { h as RuntimeClientOptions } from '../types-DAx3jHdz.cjs';
2
2
  import 'hookable';
3
3
  import 'vite';
4
4
 
@@ -1,4 +1,4 @@
1
- import { h as RuntimeClientOptions } from '../types-BKXdHkwk.js';
1
+ import { h as RuntimeClientOptions } from '../types-DAx3jHdz.js';
2
2
  import 'hookable';
3
3
  import 'vite';
4
4
 
@@ -115,25 +115,141 @@ var DEFAULT_OPTIONS = {
115
115
  import { nanoid } from "nanoid";
116
116
 
117
117
  // src/shared/serialization.ts
118
+ var RPC_CIRCULAR_VALUE = "[Circular]";
119
+ var RPC_UNREADABLE_VALUE = "[Unreadable]";
120
+ function toRpcSafeValue(value) {
121
+ return toRpcSafeChildValue(value, /* @__PURE__ */ new WeakSet(), false);
122
+ }
118
123
  function safeStringify(value) {
119
124
  if (typeof value === "string") {
120
125
  return value;
121
126
  }
122
- const seen = /* @__PURE__ */ new WeakSet();
123
- const serialized = JSON.stringify(
124
- value,
125
- (_key, current) => {
126
- if (typeof current !== "object" || current === null) {
127
- return current;
128
- }
129
- if (seen.has(current)) {
130
- return "[Circular]";
131
- }
132
- seen.add(current);
133
- return current;
127
+ const safeValue = toRpcSafeValue(value);
128
+ return safeValue === void 0 ? "undefined" : JSON.stringify(safeValue);
129
+ }
130
+ function toRpcSafeChildValue(value, seen, arrayItem) {
131
+ if (value === null) {
132
+ return null;
133
+ }
134
+ switch (typeof value) {
135
+ case "string":
136
+ case "boolean":
137
+ return value;
138
+ case "number":
139
+ return Number.isFinite(value) ? value : String(value);
140
+ case "bigint":
141
+ return value.toString();
142
+ case "symbol":
143
+ return toSymbolPlaceholder(value);
144
+ case "undefined":
145
+ case "function":
146
+ return arrayItem ? null : void 0;
147
+ case "object":
148
+ return toRpcSafeObject(value, seen);
149
+ default:
150
+ return arrayItem ? null : void 0;
151
+ }
152
+ }
153
+ function toRpcSafeObject(value, seen) {
154
+ if (seen.has(value)) {
155
+ return RPC_CIRCULAR_VALUE;
156
+ }
157
+ seen.add(value);
158
+ try {
159
+ if (value instanceof Date) {
160
+ return toSafeDate(value);
134
161
  }
135
- );
136
- return serialized;
162
+ if (value instanceof Error) {
163
+ return toSafeError(value, seen);
164
+ }
165
+ if (Array.isArray(value)) {
166
+ return toSafeArray(value, seen);
167
+ }
168
+ return toSafeRecord(value, seen);
169
+ } finally {
170
+ seen.delete(value);
171
+ }
172
+ }
173
+ function toSafeArray(values, seen) {
174
+ return values.map((item) => toRpcSafeChildValue(item, seen, true) ?? null);
175
+ }
176
+ function toSafeRecord(value, seen) {
177
+ const keys = getEnumerableKeys(value);
178
+ if (!keys) {
179
+ return RPC_UNREADABLE_VALUE;
180
+ }
181
+ if (keys.length === 0 && !isPlainRecord(value)) {
182
+ return toObjectSummary(value);
183
+ }
184
+ const result = {};
185
+ keys.forEach((key) => {
186
+ if (key === "toJSON") {
187
+ return;
188
+ }
189
+ const field = readObjectField(value, key);
190
+ if (!field.ok) {
191
+ result[key] = RPC_UNREADABLE_VALUE;
192
+ return;
193
+ }
194
+ const safeValue = toRpcSafeChildValue(field.value, seen, false);
195
+ if (safeValue !== void 0) {
196
+ result[key] = safeValue;
197
+ }
198
+ });
199
+ return result;
200
+ }
201
+ function toSafeError(error, seen) {
202
+ const result = {
203
+ name: error.name,
204
+ message: error.message
205
+ };
206
+ const stack = readObjectField(error, "stack");
207
+ if (stack.ok && typeof stack.value === "string") {
208
+ result.stack = stack.value;
209
+ }
210
+ if ("cause" in error) {
211
+ const cause = readObjectField(error, "cause");
212
+ result.cause = cause.ok ? toRpcSafeChildValue(cause.value, seen, false) ?? null : RPC_UNREADABLE_VALUE;
213
+ }
214
+ return result;
215
+ }
216
+ function toSafeDate(value) {
217
+ return Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
218
+ }
219
+ function getEnumerableKeys(value) {
220
+ try {
221
+ return Object.keys(value);
222
+ } catch {
223
+ return void 0;
224
+ }
225
+ }
226
+ function readObjectField(value, key) {
227
+ try {
228
+ return {
229
+ ok: true,
230
+ value: value[key]
231
+ };
232
+ } catch {
233
+ return { ok: false };
234
+ }
235
+ }
236
+ function isPlainRecord(value) {
237
+ try {
238
+ const prototype = Object.getPrototypeOf(value);
239
+ return prototype === Object.prototype || prototype === null;
240
+ } catch {
241
+ return false;
242
+ }
243
+ }
244
+ function toObjectSummary(value) {
245
+ try {
246
+ return Object.prototype.toString.call(value);
247
+ } catch {
248
+ return "[Object]";
249
+ }
250
+ }
251
+ function toSymbolPlaceholder(value) {
252
+ return value.description ? `[Symbol(${value.description})]` : "[Symbol]";
137
253
  }
138
254
 
139
255
  // src/runtime/consoleHook.ts
@@ -146,13 +262,14 @@ function installConsoleHook(options) {
146
262
  debug: console.debug
147
263
  };
148
264
  const emit = (level, args) => {
265
+ const serializedArgs = serializeConsoleArgs(args);
149
266
  options.send({
150
267
  id: nanoid(),
151
268
  pageId: options.pageId,
152
269
  source: "hook",
153
270
  level,
154
- message: args.map((arg) => safeStringify(arg)).join(" "),
155
- args,
271
+ message: serializedArgs.join(" "),
272
+ args: serializedArgs,
156
273
  timestamp: Date.now()
157
274
  });
158
275
  };
@@ -179,6 +296,9 @@ function installConsoleHook(options) {
179
296
  window.removeEventListener("error", onError);
180
297
  };
181
298
  }
299
+ function serializeConsoleArgs(args) {
300
+ return args.map((arg) => safeStringify(arg));
301
+ }
182
302
 
183
303
  // src/runtime/elementRegistry.ts
184
304
  import { nanoid as nanoid2 } from "nanoid";
@@ -1491,7 +1611,6 @@ import {
1491
1611
  devtoolsRouterInfo,
1492
1612
  devtoolsState,
1493
1613
  getInspector,
1494
- stringify,
1495
1614
  toggleHighPerfMode
1496
1615
  } from "@vue/devtools-kit";
1497
1616
  import { createRPCClient } from "vite-dev-rpc";
@@ -2019,6 +2138,15 @@ function installVueBridge(hot) {
2019
2138
  );
2020
2139
  rpcRef.current = rpc;
2021
2140
  }
2141
+ function toVueRpcPayload(value) {
2142
+ return toRpcSafeValue(value);
2143
+ }
2144
+ function toVueRpcJsonPayload(value) {
2145
+ return JSON.stringify(toRpcSafeValue(value) ?? null);
2146
+ }
2147
+ function toVueRpcPrettyJsonPayload(value) {
2148
+ return JSON.stringify(toRpcSafeValue(value), null, 2);
2149
+ }
2022
2150
  function createClientVueRuntimeRpc(getRpc) {
2023
2151
  return {
2024
2152
  ...createRuntimeDevtoolsRpc(getRpc),
@@ -2027,7 +2155,10 @@ function createClientVueRuntimeRpc(getRpc) {
2027
2155
  inspectorId: COMPONENTS_INSPECTOR_ID,
2028
2156
  filter: query.componentName ?? ""
2029
2157
  });
2030
- getRpc().onInspectorTreeUpdated(query.event, inspectorTree[0]);
2158
+ getRpc().onInspectorTreeUpdated(
2159
+ query.event,
2160
+ toVueRpcPayload(inspectorTree[0])
2161
+ );
2031
2162
  },
2032
2163
  onInspectorTreeUpdated: () => void 0,
2033
2164
  async getInspectorState(query) {
@@ -2035,7 +2166,7 @@ function createClientVueRuntimeRpc(getRpc) {
2035
2166
  if (!targetNode) {
2036
2167
  getRpc().onInspectorStateUpdated(
2037
2168
  query.event,
2038
- createMissingComponentError(query.componentName)
2169
+ toVueRpcPayload(createMissingComponentError(query.componentName))
2039
2170
  );
2040
2171
  return;
2041
2172
  }
@@ -2043,7 +2174,10 @@ function createClientVueRuntimeRpc(getRpc) {
2043
2174
  inspectorId: COMPONENTS_INSPECTOR_ID,
2044
2175
  nodeId: targetNode.id
2045
2176
  });
2046
- getRpc().onInspectorStateUpdated(query.event, stringify(inspectorState));
2177
+ getRpc().onInspectorStateUpdated(
2178
+ query.event,
2179
+ toVueRpcJsonPayload(inspectorState)
2180
+ );
2047
2181
  },
2048
2182
  onInspectorStateUpdated: () => void 0,
2049
2183
  async editComponentState(query) {
@@ -2080,7 +2214,7 @@ function createClientVueRuntimeRpc(getRpc) {
2080
2214
  getRouterInfo(query) {
2081
2215
  getRpc().onRouterInfoUpdated(
2082
2216
  query.event,
2083
- JSON.stringify(devtoolsRouterInfo, null, 2)
2217
+ toVueRpcPrettyJsonPayload(devtoolsRouterInfo)
2084
2218
  );
2085
2219
  },
2086
2220
  onRouterInfoUpdated: () => void 0,
@@ -2091,7 +2225,7 @@ function createClientVueRuntimeRpc(getRpc) {
2091
2225
  filter: ""
2092
2226
  })
2093
2227
  );
2094
- getRpc().onPiniaTreeUpdated(query.event, inspectorTree);
2228
+ getRpc().onPiniaTreeUpdated(query.event, toVueRpcPayload(inspectorTree));
2095
2229
  },
2096
2230
  onPiniaTreeUpdated: () => void 0,
2097
2231
  async getPiniaState(query) {
@@ -2106,7 +2240,7 @@ function createClientVueRuntimeRpc(getRpc) {
2106
2240
  }
2107
2241
  return devtools.ctx.api.getInspectorState(payload);
2108
2242
  });
2109
- getRpc().onPiniaInfoUpdated(query.event, stringify(result));
2243
+ getRpc().onPiniaInfoUpdated(query.event, toVueRpcJsonPayload(result));
2110
2244
  },
2111
2245
  onPiniaInfoUpdated: () => void 0,
2112
2246
  async recordPerformance(query) {
@@ -2114,7 +2248,7 @@ function createClientVueRuntimeRpc(getRpc) {
2114
2248
  if (!collector) {
2115
2249
  getRpc().onPerformanceRecorded(
2116
2250
  query.event,
2117
- createPerformanceUnavailableError()
2251
+ toVueRpcPayload(createPerformanceUnavailableError())
2118
2252
  );
2119
2253
  return;
2120
2254
  }
@@ -2124,11 +2258,11 @@ function createClientVueRuntimeRpc(getRpc) {
2124
2258
  includeMemory: query.includeMemory,
2125
2259
  includeStacks: query.includeStacks
2126
2260
  });
2127
- getRpc().onPerformanceRecorded(query.event, report);
2261
+ getRpc().onPerformanceRecorded(query.event, toVueRpcPayload(report));
2128
2262
  } catch (error) {
2129
2263
  getRpc().onPerformanceRecorded(
2130
2264
  query.event,
2131
- createPerformanceError(error)
2265
+ toVueRpcPayload(createPerformanceError(error))
2132
2266
  );
2133
2267
  }
2134
2268
  },
@@ -2138,7 +2272,7 @@ function createClientVueRuntimeRpc(getRpc) {
2138
2272
  if (!collector) {
2139
2273
  getRpc().onPerformanceRecordingStarted(
2140
2274
  query.event,
2141
- createPerformanceUnavailableError()
2275
+ toVueRpcPayload(createPerformanceUnavailableError())
2142
2276
  );
2143
2277
  return;
2144
2278
  }
@@ -2147,16 +2281,19 @@ function createClientVueRuntimeRpc(getRpc) {
2147
2281
  includeMemory: query.includeMemory,
2148
2282
  includeStacks: query.includeStacks
2149
2283
  });
2150
- getRpc().onPerformanceRecordingStarted(query.event, {
2151
- ok: true,
2152
- recordingId,
2153
- startedAt: Date.now(),
2154
- source: "hook"
2155
- });
2284
+ getRpc().onPerformanceRecordingStarted(
2285
+ query.event,
2286
+ toVueRpcPayload({
2287
+ ok: true,
2288
+ recordingId,
2289
+ startedAt: Date.now(),
2290
+ source: "hook"
2291
+ })
2292
+ );
2156
2293
  } catch (error) {
2157
2294
  getRpc().onPerformanceRecordingStarted(
2158
2295
  query.event,
2159
- createPerformanceError(error)
2296
+ toVueRpcPayload(createPerformanceError(error))
2160
2297
  );
2161
2298
  }
2162
2299
  },
@@ -2166,17 +2303,20 @@ function createClientVueRuntimeRpc(getRpc) {
2166
2303
  if (!collector) {
2167
2304
  getRpc().onPerformanceRecordingStopped(
2168
2305
  query.event,
2169
- createPerformanceUnavailableError()
2306
+ toVueRpcPayload(createPerformanceUnavailableError())
2170
2307
  );
2171
2308
  return;
2172
2309
  }
2173
2310
  try {
2174
2311
  const report = collector.stop(query.recordingId);
2175
- getRpc().onPerformanceRecordingStopped(query.event, report);
2312
+ getRpc().onPerformanceRecordingStopped(
2313
+ query.event,
2314
+ toVueRpcPayload(report)
2315
+ );
2176
2316
  } catch (error) {
2177
2317
  getRpc().onPerformanceRecordingStopped(
2178
2318
  query.event,
2179
- createPerformanceError(error)
2319
+ toVueRpcPayload(createPerformanceError(error))
2180
2320
  );
2181
2321
  }
2182
2322
  },