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

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,165 @@ var DEFAULT_OPTIONS = {
142
142
  var import_nanoid = require("nanoid");
143
143
 
144
144
  // src/shared/serialization.ts
145
+ var DEFAULT_PREVIEW_OPTIONS = {
146
+ maxDepth: 2,
147
+ maxKeys: 20,
148
+ maxArrayItems: 20,
149
+ maxStringLength: 1e3,
150
+ maxTotalNodes: 200
151
+ };
152
+ var CIRCULAR_VALUE = "[Circular]";
153
+ var TRUNCATED_VALUE = "[Truncated]";
154
+ var UNREADABLE_VALUE = "[Unreadable]";
155
+ function createBoundedPreview(value, options = {}) {
156
+ return previewValue(
157
+ value,
158
+ {
159
+ options: { ...DEFAULT_PREVIEW_OPTIONS, ...options },
160
+ seen: /* @__PURE__ */ new WeakSet(),
161
+ visited: 0
162
+ },
163
+ 0,
164
+ false
165
+ );
166
+ }
145
167
  function safeStringify(value) {
146
168
  if (typeof value === "string") {
169
+ return truncateString(value, DEFAULT_PREVIEW_OPTIONS.maxStringLength);
170
+ }
171
+ const preview = createBoundedPreview(value);
172
+ if (preview === void 0) {
173
+ return "undefined";
174
+ }
175
+ return JSON.stringify(preview);
176
+ }
177
+ function previewValue(value, context, depth, arrayItem) {
178
+ if (value === null) {
179
+ return null;
180
+ }
181
+ switch (typeof value) {
182
+ case "string":
183
+ return truncateString(value, context.options.maxStringLength);
184
+ case "number":
185
+ return Number.isFinite(value) ? value : String(value);
186
+ case "boolean":
187
+ return value;
188
+ case "bigint":
189
+ return value.toString();
190
+ case "symbol":
191
+ return value.description ? `[Symbol(${value.description})]` : "[Symbol]";
192
+ case "function":
193
+ return functionLabel(value);
194
+ case "undefined":
195
+ return arrayItem ? null : void 0;
196
+ case "object":
197
+ return previewObject(value, context, depth);
198
+ default:
199
+ return arrayItem ? null : void 0;
200
+ }
201
+ }
202
+ function previewObject(value, context, depth) {
203
+ if (context.seen.has(value)) {
204
+ return CIRCULAR_VALUE;
205
+ }
206
+ if (context.visited >= context.options.maxTotalNodes) {
207
+ return TRUNCATED_VALUE;
208
+ }
209
+ if (depth >= context.options.maxDepth) {
210
+ return objectLabel(value);
211
+ }
212
+ context.visited += 1;
213
+ context.seen.add(value);
214
+ if (value instanceof Date) {
215
+ return Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
216
+ }
217
+ if (value instanceof Error) {
218
+ return previewError(value, context, depth);
219
+ }
220
+ if (Array.isArray(value)) {
221
+ return previewArray(value, context, depth);
222
+ }
223
+ if (isElementLike(value)) {
224
+ return elementLabel(value);
225
+ }
226
+ return previewRecord(value, context, depth);
227
+ }
228
+ function previewArray(values, context, depth) {
229
+ const result = values.slice(0, context.options.maxArrayItems).map((item) => previewValue(item, context, depth + 1, true) ?? null);
230
+ if (values.length > context.options.maxArrayItems) {
231
+ result.push(TRUNCATED_VALUE);
232
+ }
233
+ return result;
234
+ }
235
+ function previewRecord(value, context, depth) {
236
+ const keys = enumerableKeys(value);
237
+ if (!keys) {
238
+ return UNREADABLE_VALUE;
239
+ }
240
+ const result = {};
241
+ const limitedKeys = keys.filter((key) => key !== "toJSON");
242
+ limitedKeys.slice(0, context.options.maxKeys).forEach((key) => {
243
+ const field = readField(value, key);
244
+ result[key] = field.ok ? previewValue(field.value, context, depth + 1, false) ?? null : UNREADABLE_VALUE;
245
+ });
246
+ if (limitedKeys.length > context.options.maxKeys) {
247
+ result[TRUNCATED_VALUE] = `${String(limitedKeys.length - context.options.maxKeys)} keys omitted`;
248
+ }
249
+ return result;
250
+ }
251
+ function previewError(error, context, depth) {
252
+ const result = {
253
+ name: error.name,
254
+ message: truncateString(error.message, context.options.maxStringLength)
255
+ };
256
+ const stack = readField(error, "stack");
257
+ if (stack.ok && typeof stack.value === "string") {
258
+ result.stack = truncateString(stack.value, context.options.maxStringLength);
259
+ }
260
+ const cause = readField(error, "cause");
261
+ if (cause.ok && cause.value !== void 0) {
262
+ result.cause = previewValue(cause.value, context, depth + 1, false) ?? null;
263
+ }
264
+ return result;
265
+ }
266
+ function enumerableKeys(value) {
267
+ try {
268
+ return Object.keys(value);
269
+ } catch {
270
+ return void 0;
271
+ }
272
+ }
273
+ function readField(value, key) {
274
+ try {
275
+ return { ok: true, value: value[key] };
276
+ } catch {
277
+ return { ok: false };
278
+ }
279
+ }
280
+ function truncateString(value, maxLength) {
281
+ if (value.length <= maxLength) {
147
282
  return value;
148
283
  }
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;
161
- }
162
- );
163
- return serialized;
284
+ return `${value.slice(0, maxLength)}${TRUNCATED_VALUE}`;
285
+ }
286
+ function functionLabel(value) {
287
+ return value.name ? `[Function:${value.name}]` : "[Function]";
288
+ }
289
+ function objectLabel(value) {
290
+ if (Array.isArray(value)) {
291
+ return `[Array(${String(value.length)})]`;
292
+ }
293
+ return "[Object]";
294
+ }
295
+ function isElementLike(value) {
296
+ const node = value;
297
+ return node.nodeType === 1 && typeof node.nodeName === "string";
298
+ }
299
+ function elementLabel(value) {
300
+ const name = value.nodeName.toLowerCase();
301
+ const id = value.id ? `#${value.id}` : "";
302
+ const className = typeof value.className === "string" && value.className ? `.${value.className.trim().replace(/\s+/g, ".")}` : "";
303
+ return `[Element:${name}${id}${className}]`;
164
304
  }
165
305
 
166
306
  // src/runtime/consoleHook.ts
@@ -179,7 +319,7 @@ function installConsoleHook(options) {
179
319
  source: "hook",
180
320
  level,
181
321
  message: args.map((arg) => safeStringify(arg)).join(" "),
182
- args,
322
+ args: args.map((arg) => createBoundedPreview(arg)),
183
323
  timestamp: Date.now()
184
324
  });
185
325
  };
@@ -269,7 +409,7 @@ function installElementPicker(options) {
269
409
  window.addEventListener(
270
410
  "click",
271
411
  (event) => {
272
- if (!active || !isElementLike(event.target)) {
412
+ if (!active || !isElementLike2(event.target)) {
273
413
  return;
274
414
  }
275
415
  event.preventDefault();
@@ -351,7 +491,7 @@ function showToast(message, durationMs) {
351
491
  toast.remove();
352
492
  }, durationMs);
353
493
  }
354
- function isElementLike(value) {
494
+ function isElementLike2(value) {
355
495
  return Boolean(
356
496
  value && typeof value === "object" && "getAttribute" in value && "getBoundingClientRect" in value
357
497
  );
@@ -2020,6 +2160,18 @@ function createRuntimeDevtoolsRpc(getRpc) {
2020
2160
  var PINIA_INSPECTOR_ID = "pinia";
2021
2161
  var COMPONENTS_INSPECTOR_ID = "components";
2022
2162
  var COMPONENT_HIGHLIGHT_DURATION = 5e3;
2163
+ var INSPECTOR_TREE_MAX_DEPTH = 20;
2164
+ var INSPECTOR_TREE_MAX_NODES = 500;
2165
+ var INSPECTOR_TREE_MAX_CHILDREN = 200;
2166
+ var INSPECTOR_TREE_MAX_TAGS = 20;
2167
+ var INSPECTOR_NODE_FIELDS = [
2168
+ "id",
2169
+ "label",
2170
+ "name",
2171
+ "inactive",
2172
+ "isFragment",
2173
+ "autoOpen"
2174
+ ];
2023
2175
  var highlightComponentTimeout;
2024
2176
  function initializeVueDevtoolsHook() {
2025
2177
  import_devtools_kit.devtools.init();
@@ -2039,6 +2191,65 @@ function installVueBridge(hot) {
2039
2191
  );
2040
2192
  rpcRef.current = rpc;
2041
2193
  }
2194
+ function projectInspectorTreeList(value) {
2195
+ if (!Array.isArray(value)) {
2196
+ return [];
2197
+ }
2198
+ const budget = { visited: 0 };
2199
+ return value.map((node) => projectInspectorNode(node, budget, 0));
2200
+ }
2201
+ function projectInspectorNode(value, budget, depth) {
2202
+ if (!value || typeof value !== "object") {
2203
+ return value;
2204
+ }
2205
+ if (budget.visited >= INSPECTOR_TREE_MAX_NODES || depth >= INSPECTOR_TREE_MAX_DEPTH) {
2206
+ return "[Truncated]";
2207
+ }
2208
+ budget.visited += 1;
2209
+ const result = {};
2210
+ INSPECTOR_NODE_FIELDS.forEach((field) => {
2211
+ const valueField = readInspectorField(value, field);
2212
+ if (valueField.ok && isInspectorPrimitive(valueField.value)) {
2213
+ result[field] = valueField.value;
2214
+ }
2215
+ });
2216
+ const tags = readInspectorField(value, "tags");
2217
+ if (tags.ok && Array.isArray(tags.value)) {
2218
+ result.tags = tags.value.slice(0, INSPECTOR_TREE_MAX_TAGS).map(projectInspectorTag);
2219
+ }
2220
+ const children = readInspectorField(value, "children");
2221
+ if (children.ok && Array.isArray(children.value)) {
2222
+ const projectedChildren = children.value.slice(0, INSPECTOR_TREE_MAX_CHILDREN).map((child) => projectInspectorNode(child, budget, depth + 1));
2223
+ if (children.value.length > INSPECTOR_TREE_MAX_CHILDREN) {
2224
+ projectedChildren.push("[Truncated]");
2225
+ }
2226
+ result.children = projectedChildren;
2227
+ }
2228
+ return result;
2229
+ }
2230
+ function projectInspectorTag(value) {
2231
+ if (!value || typeof value !== "object") {
2232
+ return value;
2233
+ }
2234
+ const result = {};
2235
+ Object.keys(value).filter((key) => key !== "toJSON").slice(0, 8).forEach((key) => {
2236
+ const field = readInspectorField(value, key);
2237
+ if (field.ok && isInspectorPrimitive(field.value)) {
2238
+ result[key] = field.value;
2239
+ }
2240
+ });
2241
+ return result;
2242
+ }
2243
+ function readInspectorField(value, key) {
2244
+ try {
2245
+ return { ok: true, value: value[key] };
2246
+ } catch {
2247
+ return { ok: false };
2248
+ }
2249
+ }
2250
+ function isInspectorPrimitive(value) {
2251
+ return typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null;
2252
+ }
2042
2253
  function createClientVueRuntimeRpc(getRpc) {
2043
2254
  return {
2044
2255
  ...createRuntimeDevtoolsRpc(getRpc),
@@ -2047,7 +2258,10 @@ function createClientVueRuntimeRpc(getRpc) {
2047
2258
  inspectorId: COMPONENTS_INSPECTOR_ID,
2048
2259
  filter: query.componentName ?? ""
2049
2260
  });
2050
- getRpc().onInspectorTreeUpdated(query.event, inspectorTree[0]);
2261
+ getRpc().onInspectorTreeUpdated(
2262
+ query.event,
2263
+ projectInspectorNode(inspectorTree[0], { visited: 0 }, 0)
2264
+ );
2051
2265
  },
2052
2266
  onInspectorTreeUpdated: () => void 0,
2053
2267
  async getInspectorState(query) {
@@ -2111,7 +2325,10 @@ function createClientVueRuntimeRpc(getRpc) {
2111
2325
  filter: ""
2112
2326
  })
2113
2327
  );
2114
- getRpc().onPiniaTreeUpdated(query.event, inspectorTree);
2328
+ getRpc().onPiniaTreeUpdated(
2329
+ query.event,
2330
+ projectInspectorTreeList(inspectorTree)
2331
+ );
2115
2332
  },
2116
2333
  onPiniaTreeUpdated: () => void 0,
2117
2334
  async getPiniaState(query) {