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