ms-vite-plugin 1.1.13 → 1.1.14

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.
Files changed (2) hide show
  1. package/dist/mcp/tools.js +82 -13
  2. package/package.json +1 -1
package/dist/mcp/tools.js CHANGED
@@ -369,33 +369,102 @@ function ensureDeviceLogSubscription(ip, port) {
369
369
  * const text = buildDeviceLogSnapshotText(100, 20)
370
370
  */
371
371
  function buildDeviceLogSnapshotText(limit, runtimeStatusLimit) {
372
- const targetText = deviceLogSubscriptionState.target
373
- ? `${deviceLogSubscriptionState.target.ip}:${deviceLogSubscriptionState.target.port}`
374
- : "未订阅";
375
372
  const recentLogs = deviceLogSubscriptionState.logs
376
373
  .slice(-limit)
377
374
  .map((log) => `[${log.timestamp}] [${log.level.toUpperCase()}] ${log.message}`);
378
375
  const recentRuntimeStatus = deviceLogSubscriptionState.runtimeStatus
379
376
  .slice(-runtimeStatusLimit)
380
- .map((entry) => `[${entry.timestamp}] ${JSON.stringify(entry.raw, null, 2).replace(/\n/g, " ")}`);
377
+ .map((entry) => formatRuntimeStatusEntry(entry));
381
378
  return [
382
- `订阅目标: ${targetText}`,
383
- `连接状态: ${deviceLogSubscriptionState.status}`,
384
- `缓存日志: ${deviceLogSubscriptionState.logs.length}/${DEVICE_LOG_MEMORY_LIMIT}`,
385
- `缓存 runtime_status: ${deviceLogSubscriptionState.runtimeStatus.length}/${DEVICE_LOG_MEMORY_LIMIT}`,
386
- `startedAt: ${deviceLogSubscriptionState.startedAt ?? "unknown"}`,
387
- `lastEventAt: ${deviceLogSubscriptionState.lastEventAt ?? "unknown"}`,
388
- `lastError: ${deviceLogSubscriptionState.lastError ?? "none"}`,
379
+ `设备: ${deviceLogSubscriptionState.target
380
+ ? `${deviceLogSubscriptionState.target.ip}:${deviceLogSubscriptionState.target.port}`
381
+ : "未订阅"}`,
382
+ `状态: ${formatDeviceLogSubscriptionStatus(deviceLogSubscriptionState.status)}`,
383
+ ...(deviceLogSubscriptionState.lastError
384
+ ? [`最近错误: ${deviceLogSubscriptionState.lastError}`]
385
+ : []),
389
386
  "",
390
387
  `最新日志(最多 ${limit} 条):`,
391
388
  recentLogs.length > 0 ? recentLogs.join("\n") : "无日志",
392
389
  "",
393
- `最新 runtime_status(最多 ${runtimeStatusLimit} 条):`,
390
+ `最新运行状态(最多 ${runtimeStatusLimit} 条):`,
394
391
  recentRuntimeStatus.length > 0
395
392
  ? recentRuntimeStatus.join("\n")
396
- : "无 runtime_status",
393
+ : "无运行状态",
397
394
  ].join("\n");
398
395
  }
396
+ /**
397
+ * 将日志订阅连接状态转为中文文本
398
+ * @param status 原始连接状态
399
+ * @returns 返回中文状态说明
400
+ * @example
401
+ * formatDeviceLogSubscriptionStatus("connected")
402
+ */
403
+ function formatDeviceLogSubscriptionStatus(status) {
404
+ switch (status) {
405
+ case "idle":
406
+ return "未订阅";
407
+ case "connecting":
408
+ return "连接中";
409
+ case "connected":
410
+ return "已连接";
411
+ case "reconnecting":
412
+ return "重连中";
413
+ case "error":
414
+ return "连接异常";
415
+ default:
416
+ return status;
417
+ }
418
+ }
419
+ /**
420
+ * 将 runtime_status 中的布尔值转为中文状态文本
421
+ * @param value 原始布尔值
422
+ * @returns true 返回“是”,false 返回“否”,其它情况返回“unknown”
423
+ * @example
424
+ * formatBooleanStatusText(true)
425
+ */
426
+ function formatBooleanStatusText(value) {
427
+ if (typeof value === "boolean") {
428
+ return value ? "是" : "否";
429
+ }
430
+ return "未知";
431
+ }
432
+ /**
433
+ * 将 runtime_status 中的内存数值格式化为可读文本
434
+ * @param value 原始数值
435
+ * @param suffix 数值单位后缀
436
+ * @returns 数值存在时返回格式化结果,否则返回 unknown
437
+ * @example
438
+ * formatRuntimeMetricText(12.3456, " MB")
439
+ */
440
+ function formatRuntimeMetricText(value, suffix = "") {
441
+ if (typeof value === "number" && Number.isFinite(value)) {
442
+ return `${value.toFixed(2)}${suffix}`;
443
+ }
444
+ return "未知";
445
+ }
446
+ /**
447
+ * 将单条 runtime_status 事件格式化为中文运行状态摘要
448
+ * @param entry runtime_status 条目
449
+ * @returns 返回更易读的状态文本
450
+ * @example
451
+ * formatRuntimeStatusEntry({ raw: { isRunning: false }, timestamp: "2026-01-01T00:00:00.000Z" })
452
+ */
453
+ function formatRuntimeStatusEntry(entry) {
454
+ const raw = entry.raw;
455
+ const memory = raw.memory && typeof raw.memory === "object"
456
+ ? raw.memory
457
+ : {};
458
+ return [
459
+ `[${entry.timestamp}]`,
460
+ `UI: ${formatBooleanStatusText(raw.isUIShowing)}`,
461
+ `脚本: ${formatBooleanStatusText(raw.isRunning)}`,
462
+ `总内存: ${formatRuntimeMetricText(memory.total, " MB")}`,
463
+ `可用: ${formatRuntimeMetricText(memory.available, " MB")}`,
464
+ `已用: ${formatRuntimeMetricText(memory.used, " MB")}`,
465
+ `占用: ${formatRuntimeMetricText(memory.usagePercentage, "%")}`,
466
+ ].join(" | ");
467
+ }
399
468
  /**
400
469
  * 格式化单条 API 文档摘要
401
470
  * @param language 文档语言
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ms-vite-plugin",
3
- "version": "1.1.13",
3
+ "version": "1.1.14",
4
4
  "type": "commonjs",
5
5
  "license": "MIT",
6
6
  "publishConfig": {