@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.
@@ -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
@@ -1495,7 +1611,6 @@ import {
1495
1611
  devtoolsRouterInfo,
1496
1612
  devtoolsState,
1497
1613
  getInspector,
1498
- stringify,
1499
1614
  toggleHighPerfMode
1500
1615
  } from "@vue/devtools-kit";
1501
1616
  import { createRPCClient } from "vite-dev-rpc";
@@ -2023,6 +2138,15 @@ function installVueBridge(hot) {
2023
2138
  );
2024
2139
  rpcRef.current = rpc;
2025
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
+ }
2026
2150
  function createClientVueRuntimeRpc(getRpc) {
2027
2151
  return {
2028
2152
  ...createRuntimeDevtoolsRpc(getRpc),
@@ -2031,7 +2155,10 @@ function createClientVueRuntimeRpc(getRpc) {
2031
2155
  inspectorId: COMPONENTS_INSPECTOR_ID,
2032
2156
  filter: query.componentName ?? ""
2033
2157
  });
2034
- getRpc().onInspectorTreeUpdated(query.event, inspectorTree[0]);
2158
+ getRpc().onInspectorTreeUpdated(
2159
+ query.event,
2160
+ toVueRpcPayload(inspectorTree[0])
2161
+ );
2035
2162
  },
2036
2163
  onInspectorTreeUpdated: () => void 0,
2037
2164
  async getInspectorState(query) {
@@ -2039,7 +2166,7 @@ function createClientVueRuntimeRpc(getRpc) {
2039
2166
  if (!targetNode) {
2040
2167
  getRpc().onInspectorStateUpdated(
2041
2168
  query.event,
2042
- createMissingComponentError(query.componentName)
2169
+ toVueRpcPayload(createMissingComponentError(query.componentName))
2043
2170
  );
2044
2171
  return;
2045
2172
  }
@@ -2047,7 +2174,10 @@ function createClientVueRuntimeRpc(getRpc) {
2047
2174
  inspectorId: COMPONENTS_INSPECTOR_ID,
2048
2175
  nodeId: targetNode.id
2049
2176
  });
2050
- getRpc().onInspectorStateUpdated(query.event, stringify(inspectorState));
2177
+ getRpc().onInspectorStateUpdated(
2178
+ query.event,
2179
+ toVueRpcJsonPayload(inspectorState)
2180
+ );
2051
2181
  },
2052
2182
  onInspectorStateUpdated: () => void 0,
2053
2183
  async editComponentState(query) {
@@ -2084,7 +2214,7 @@ function createClientVueRuntimeRpc(getRpc) {
2084
2214
  getRouterInfo(query) {
2085
2215
  getRpc().onRouterInfoUpdated(
2086
2216
  query.event,
2087
- JSON.stringify(devtoolsRouterInfo, null, 2)
2217
+ toVueRpcPrettyJsonPayload(devtoolsRouterInfo)
2088
2218
  );
2089
2219
  },
2090
2220
  onRouterInfoUpdated: () => void 0,
@@ -2095,7 +2225,7 @@ function createClientVueRuntimeRpc(getRpc) {
2095
2225
  filter: ""
2096
2226
  })
2097
2227
  );
2098
- getRpc().onPiniaTreeUpdated(query.event, inspectorTree);
2228
+ getRpc().onPiniaTreeUpdated(query.event, toVueRpcPayload(inspectorTree));
2099
2229
  },
2100
2230
  onPiniaTreeUpdated: () => void 0,
2101
2231
  async getPiniaState(query) {
@@ -2110,7 +2240,7 @@ function createClientVueRuntimeRpc(getRpc) {
2110
2240
  }
2111
2241
  return devtools.ctx.api.getInspectorState(payload);
2112
2242
  });
2113
- getRpc().onPiniaInfoUpdated(query.event, stringify(result));
2243
+ getRpc().onPiniaInfoUpdated(query.event, toVueRpcJsonPayload(result));
2114
2244
  },
2115
2245
  onPiniaInfoUpdated: () => void 0,
2116
2246
  async recordPerformance(query) {
@@ -2118,7 +2248,7 @@ function createClientVueRuntimeRpc(getRpc) {
2118
2248
  if (!collector) {
2119
2249
  getRpc().onPerformanceRecorded(
2120
2250
  query.event,
2121
- createPerformanceUnavailableError()
2251
+ toVueRpcPayload(createPerformanceUnavailableError())
2122
2252
  );
2123
2253
  return;
2124
2254
  }
@@ -2128,11 +2258,11 @@ function createClientVueRuntimeRpc(getRpc) {
2128
2258
  includeMemory: query.includeMemory,
2129
2259
  includeStacks: query.includeStacks
2130
2260
  });
2131
- getRpc().onPerformanceRecorded(query.event, report);
2261
+ getRpc().onPerformanceRecorded(query.event, toVueRpcPayload(report));
2132
2262
  } catch (error) {
2133
2263
  getRpc().onPerformanceRecorded(
2134
2264
  query.event,
2135
- createPerformanceError(error)
2265
+ toVueRpcPayload(createPerformanceError(error))
2136
2266
  );
2137
2267
  }
2138
2268
  },
@@ -2142,7 +2272,7 @@ function createClientVueRuntimeRpc(getRpc) {
2142
2272
  if (!collector) {
2143
2273
  getRpc().onPerformanceRecordingStarted(
2144
2274
  query.event,
2145
- createPerformanceUnavailableError()
2275
+ toVueRpcPayload(createPerformanceUnavailableError())
2146
2276
  );
2147
2277
  return;
2148
2278
  }
@@ -2151,16 +2281,19 @@ function createClientVueRuntimeRpc(getRpc) {
2151
2281
  includeMemory: query.includeMemory,
2152
2282
  includeStacks: query.includeStacks
2153
2283
  });
2154
- getRpc().onPerformanceRecordingStarted(query.event, {
2155
- ok: true,
2156
- recordingId,
2157
- startedAt: Date.now(),
2158
- source: "hook"
2159
- });
2284
+ getRpc().onPerformanceRecordingStarted(
2285
+ query.event,
2286
+ toVueRpcPayload({
2287
+ ok: true,
2288
+ recordingId,
2289
+ startedAt: Date.now(),
2290
+ source: "hook"
2291
+ })
2292
+ );
2160
2293
  } catch (error) {
2161
2294
  getRpc().onPerformanceRecordingStarted(
2162
2295
  query.event,
2163
- createPerformanceError(error)
2296
+ toVueRpcPayload(createPerformanceError(error))
2164
2297
  );
2165
2298
  }
2166
2299
  },
@@ -2170,17 +2303,20 @@ function createClientVueRuntimeRpc(getRpc) {
2170
2303
  if (!collector) {
2171
2304
  getRpc().onPerformanceRecordingStopped(
2172
2305
  query.event,
2173
- createPerformanceUnavailableError()
2306
+ toVueRpcPayload(createPerformanceUnavailableError())
2174
2307
  );
2175
2308
  return;
2176
2309
  }
2177
2310
  try {
2178
2311
  const report = collector.stop(query.recordingId);
2179
- getRpc().onPerformanceRecordingStopped(query.event, report);
2312
+ getRpc().onPerformanceRecordingStopped(
2313
+ query.event,
2314
+ toVueRpcPayload(report)
2315
+ );
2180
2316
  } catch (error) {
2181
2317
  getRpc().onPerformanceRecordingStopped(
2182
2318
  query.event,
2183
- createPerformanceError(error)
2319
+ toVueRpcPayload(createPerformanceError(error))
2184
2320
  );
2185
2321
  }
2186
2322
  },