@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.
@@ -115,25 +115,165 @@ var DEFAULT_OPTIONS = {
115
115
  import { nanoid } from "nanoid";
116
116
 
117
117
  // src/shared/serialization.ts
118
+ var DEFAULT_PREVIEW_OPTIONS = {
119
+ maxDepth: 2,
120
+ maxKeys: 20,
121
+ maxArrayItems: 20,
122
+ maxStringLength: 1e3,
123
+ maxTotalNodes: 200
124
+ };
125
+ var CIRCULAR_VALUE = "[Circular]";
126
+ var TRUNCATED_VALUE = "[Truncated]";
127
+ var UNREADABLE_VALUE = "[Unreadable]";
128
+ function createBoundedPreview(value, options = {}) {
129
+ return previewValue(
130
+ value,
131
+ {
132
+ options: { ...DEFAULT_PREVIEW_OPTIONS, ...options },
133
+ seen: /* @__PURE__ */ new WeakSet(),
134
+ visited: 0
135
+ },
136
+ 0,
137
+ false
138
+ );
139
+ }
118
140
  function safeStringify(value) {
119
141
  if (typeof value === "string") {
142
+ return truncateString(value, DEFAULT_PREVIEW_OPTIONS.maxStringLength);
143
+ }
144
+ const preview = createBoundedPreview(value);
145
+ if (preview === void 0) {
146
+ return "undefined";
147
+ }
148
+ return JSON.stringify(preview);
149
+ }
150
+ function previewValue(value, context, depth, arrayItem) {
151
+ if (value === null) {
152
+ return null;
153
+ }
154
+ switch (typeof value) {
155
+ case "string":
156
+ return truncateString(value, context.options.maxStringLength);
157
+ case "number":
158
+ return Number.isFinite(value) ? value : String(value);
159
+ case "boolean":
160
+ return value;
161
+ case "bigint":
162
+ return value.toString();
163
+ case "symbol":
164
+ return value.description ? `[Symbol(${value.description})]` : "[Symbol]";
165
+ case "function":
166
+ return functionLabel(value);
167
+ case "undefined":
168
+ return arrayItem ? null : void 0;
169
+ case "object":
170
+ return previewObject(value, context, depth);
171
+ default:
172
+ return arrayItem ? null : void 0;
173
+ }
174
+ }
175
+ function previewObject(value, context, depth) {
176
+ if (context.seen.has(value)) {
177
+ return CIRCULAR_VALUE;
178
+ }
179
+ if (context.visited >= context.options.maxTotalNodes) {
180
+ return TRUNCATED_VALUE;
181
+ }
182
+ if (depth >= context.options.maxDepth) {
183
+ return objectLabel(value);
184
+ }
185
+ context.visited += 1;
186
+ context.seen.add(value);
187
+ if (value instanceof Date) {
188
+ return Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
189
+ }
190
+ if (value instanceof Error) {
191
+ return previewError(value, context, depth);
192
+ }
193
+ if (Array.isArray(value)) {
194
+ return previewArray(value, context, depth);
195
+ }
196
+ if (isElementLike(value)) {
197
+ return elementLabel(value);
198
+ }
199
+ return previewRecord(value, context, depth);
200
+ }
201
+ function previewArray(values, context, depth) {
202
+ const result = values.slice(0, context.options.maxArrayItems).map((item) => previewValue(item, context, depth + 1, true) ?? null);
203
+ if (values.length > context.options.maxArrayItems) {
204
+ result.push(TRUNCATED_VALUE);
205
+ }
206
+ return result;
207
+ }
208
+ function previewRecord(value, context, depth) {
209
+ const keys = enumerableKeys(value);
210
+ if (!keys) {
211
+ return UNREADABLE_VALUE;
212
+ }
213
+ const result = {};
214
+ const limitedKeys = keys.filter((key) => key !== "toJSON");
215
+ limitedKeys.slice(0, context.options.maxKeys).forEach((key) => {
216
+ const field = readField(value, key);
217
+ result[key] = field.ok ? previewValue(field.value, context, depth + 1, false) ?? null : UNREADABLE_VALUE;
218
+ });
219
+ if (limitedKeys.length > context.options.maxKeys) {
220
+ result[TRUNCATED_VALUE] = `${String(limitedKeys.length - context.options.maxKeys)} keys omitted`;
221
+ }
222
+ return result;
223
+ }
224
+ function previewError(error, context, depth) {
225
+ const result = {
226
+ name: error.name,
227
+ message: truncateString(error.message, context.options.maxStringLength)
228
+ };
229
+ const stack = readField(error, "stack");
230
+ if (stack.ok && typeof stack.value === "string") {
231
+ result.stack = truncateString(stack.value, context.options.maxStringLength);
232
+ }
233
+ const cause = readField(error, "cause");
234
+ if (cause.ok && cause.value !== void 0) {
235
+ result.cause = previewValue(cause.value, context, depth + 1, false) ?? null;
236
+ }
237
+ return result;
238
+ }
239
+ function enumerableKeys(value) {
240
+ try {
241
+ return Object.keys(value);
242
+ } catch {
243
+ return void 0;
244
+ }
245
+ }
246
+ function readField(value, key) {
247
+ try {
248
+ return { ok: true, value: value[key] };
249
+ } catch {
250
+ return { ok: false };
251
+ }
252
+ }
253
+ function truncateString(value, maxLength) {
254
+ if (value.length <= maxLength) {
120
255
  return value;
121
256
  }
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;
134
- }
135
- );
136
- return serialized;
257
+ return `${value.slice(0, maxLength)}${TRUNCATED_VALUE}`;
258
+ }
259
+ function functionLabel(value) {
260
+ return value.name ? `[Function:${value.name}]` : "[Function]";
261
+ }
262
+ function objectLabel(value) {
263
+ if (Array.isArray(value)) {
264
+ return `[Array(${String(value.length)})]`;
265
+ }
266
+ return "[Object]";
267
+ }
268
+ function isElementLike(value) {
269
+ const node = value;
270
+ return node.nodeType === 1 && typeof node.nodeName === "string";
271
+ }
272
+ function elementLabel(value) {
273
+ const name = value.nodeName.toLowerCase();
274
+ const id = value.id ? `#${value.id}` : "";
275
+ const className = typeof value.className === "string" && value.className ? `.${value.className.trim().replace(/\s+/g, ".")}` : "";
276
+ return `[Element:${name}${id}${className}]`;
137
277
  }
138
278
 
139
279
  // src/runtime/consoleHook.ts
@@ -152,7 +292,7 @@ function installConsoleHook(options) {
152
292
  source: "hook",
153
293
  level,
154
294
  message: args.map((arg) => safeStringify(arg)).join(" "),
155
- args,
295
+ args: args.map((arg) => createBoundedPreview(arg)),
156
296
  timestamp: Date.now()
157
297
  });
158
298
  };
@@ -242,7 +382,7 @@ function installElementPicker(options) {
242
382
  window.addEventListener(
243
383
  "click",
244
384
  (event) => {
245
- if (!active || !isElementLike(event.target)) {
385
+ if (!active || !isElementLike2(event.target)) {
246
386
  return;
247
387
  }
248
388
  event.preventDefault();
@@ -324,7 +464,7 @@ function showToast(message, durationMs) {
324
464
  toast.remove();
325
465
  }, durationMs);
326
466
  }
327
- function isElementLike(value) {
467
+ function isElementLike2(value) {
328
468
  return Boolean(
329
469
  value && typeof value === "object" && "getAttribute" in value && "getBoundingClientRect" in value
330
470
  );
@@ -2000,6 +2140,18 @@ function createRuntimeDevtoolsRpc(getRpc) {
2000
2140
  var PINIA_INSPECTOR_ID = "pinia";
2001
2141
  var COMPONENTS_INSPECTOR_ID = "components";
2002
2142
  var COMPONENT_HIGHLIGHT_DURATION = 5e3;
2143
+ var INSPECTOR_TREE_MAX_DEPTH = 20;
2144
+ var INSPECTOR_TREE_MAX_NODES = 500;
2145
+ var INSPECTOR_TREE_MAX_CHILDREN = 200;
2146
+ var INSPECTOR_TREE_MAX_TAGS = 20;
2147
+ var INSPECTOR_NODE_FIELDS = [
2148
+ "id",
2149
+ "label",
2150
+ "name",
2151
+ "inactive",
2152
+ "isFragment",
2153
+ "autoOpen"
2154
+ ];
2003
2155
  var highlightComponentTimeout;
2004
2156
  function initializeVueDevtoolsHook() {
2005
2157
  devtools.init();
@@ -2019,6 +2171,65 @@ function installVueBridge(hot) {
2019
2171
  );
2020
2172
  rpcRef.current = rpc;
2021
2173
  }
2174
+ function projectInspectorTreeList(value) {
2175
+ if (!Array.isArray(value)) {
2176
+ return [];
2177
+ }
2178
+ const budget = { visited: 0 };
2179
+ return value.map((node) => projectInspectorNode(node, budget, 0));
2180
+ }
2181
+ function projectInspectorNode(value, budget, depth) {
2182
+ if (!value || typeof value !== "object") {
2183
+ return value;
2184
+ }
2185
+ if (budget.visited >= INSPECTOR_TREE_MAX_NODES || depth >= INSPECTOR_TREE_MAX_DEPTH) {
2186
+ return "[Truncated]";
2187
+ }
2188
+ budget.visited += 1;
2189
+ const result = {};
2190
+ INSPECTOR_NODE_FIELDS.forEach((field) => {
2191
+ const valueField = readInspectorField(value, field);
2192
+ if (valueField.ok && isInspectorPrimitive(valueField.value)) {
2193
+ result[field] = valueField.value;
2194
+ }
2195
+ });
2196
+ const tags = readInspectorField(value, "tags");
2197
+ if (tags.ok && Array.isArray(tags.value)) {
2198
+ result.tags = tags.value.slice(0, INSPECTOR_TREE_MAX_TAGS).map(projectInspectorTag);
2199
+ }
2200
+ const children = readInspectorField(value, "children");
2201
+ if (children.ok && Array.isArray(children.value)) {
2202
+ const projectedChildren = children.value.slice(0, INSPECTOR_TREE_MAX_CHILDREN).map((child) => projectInspectorNode(child, budget, depth + 1));
2203
+ if (children.value.length > INSPECTOR_TREE_MAX_CHILDREN) {
2204
+ projectedChildren.push("[Truncated]");
2205
+ }
2206
+ result.children = projectedChildren;
2207
+ }
2208
+ return result;
2209
+ }
2210
+ function projectInspectorTag(value) {
2211
+ if (!value || typeof value !== "object") {
2212
+ return value;
2213
+ }
2214
+ const result = {};
2215
+ Object.keys(value).filter((key) => key !== "toJSON").slice(0, 8).forEach((key) => {
2216
+ const field = readInspectorField(value, key);
2217
+ if (field.ok && isInspectorPrimitive(field.value)) {
2218
+ result[key] = field.value;
2219
+ }
2220
+ });
2221
+ return result;
2222
+ }
2223
+ function readInspectorField(value, key) {
2224
+ try {
2225
+ return { ok: true, value: value[key] };
2226
+ } catch {
2227
+ return { ok: false };
2228
+ }
2229
+ }
2230
+ function isInspectorPrimitive(value) {
2231
+ return typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null;
2232
+ }
2022
2233
  function createClientVueRuntimeRpc(getRpc) {
2023
2234
  return {
2024
2235
  ...createRuntimeDevtoolsRpc(getRpc),
@@ -2027,7 +2238,10 @@ function createClientVueRuntimeRpc(getRpc) {
2027
2238
  inspectorId: COMPONENTS_INSPECTOR_ID,
2028
2239
  filter: query.componentName ?? ""
2029
2240
  });
2030
- getRpc().onInspectorTreeUpdated(query.event, inspectorTree[0]);
2241
+ getRpc().onInspectorTreeUpdated(
2242
+ query.event,
2243
+ projectInspectorNode(inspectorTree[0], { visited: 0 }, 0)
2244
+ );
2031
2245
  },
2032
2246
  onInspectorTreeUpdated: () => void 0,
2033
2247
  async getInspectorState(query) {
@@ -2091,7 +2305,10 @@ function createClientVueRuntimeRpc(getRpc) {
2091
2305
  filter: ""
2092
2306
  })
2093
2307
  );
2094
- getRpc().onPiniaTreeUpdated(query.event, inspectorTree);
2308
+ getRpc().onPiniaTreeUpdated(
2309
+ query.event,
2310
+ projectInspectorTreeList(inspectorTree)
2311
+ );
2095
2312
  },
2096
2313
  onPiniaTreeUpdated: () => void 0,
2097
2314
  async getPiniaState(query) {