ms-vite-plugin 1.1.13 → 1.1.15
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.
- package/dist/mcp/tools.js +77 -13
- package/package.json +1 -1
package/dist/mcp/tools.js
CHANGED
|
@@ -369,33 +369,97 @@ 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) =>
|
|
377
|
+
.map((entry) => formatRuntimeStatusEntry(entry));
|
|
381
378
|
return [
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
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
|
-
|
|
390
|
+
`最新运行状态(最多 ${runtimeStatusLimit} 条):`,
|
|
394
391
|
recentRuntimeStatus.length > 0
|
|
395
392
|
? recentRuntimeStatus.join("\n")
|
|
396
|
-
: "
|
|
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
|
+
* @param suffix 数值单位后缀
|
|
423
|
+
* @returns 数值存在时返回格式化结果,否则返回 unknown
|
|
424
|
+
* @example
|
|
425
|
+
* formatRuntimeMetricText(12.3456, " MB")
|
|
426
|
+
*/
|
|
427
|
+
function formatRuntimeMetricText(value, suffix = "") {
|
|
428
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
429
|
+
return `${value.toFixed(2)}${suffix}`;
|
|
430
|
+
}
|
|
431
|
+
return "未知";
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* 将单条 runtime_status 事件格式化为中文运行状态摘要
|
|
435
|
+
* @param entry runtime_status 条目
|
|
436
|
+
* @returns 返回更易读的状态文本
|
|
437
|
+
* @example
|
|
438
|
+
* formatRuntimeStatusEntry({ raw: { isRunning: false }, timestamp: "2026-01-01T00:00:00.000Z" })
|
|
439
|
+
*/
|
|
440
|
+
function formatRuntimeStatusEntry(entry) {
|
|
441
|
+
const raw = entry.raw;
|
|
442
|
+
const memory = raw.memory && typeof raw.memory === "object"
|
|
443
|
+
? raw.memory
|
|
444
|
+
: {};
|
|
445
|
+
return [
|
|
446
|
+
`[${entry.timestamp}]`,
|
|
447
|
+
`UI: ${typeof raw.isUIShowing === "boolean"
|
|
448
|
+
? raw.isUIShowing
|
|
449
|
+
? "显示中"
|
|
450
|
+
: "未显示"
|
|
451
|
+
: "未知"}`,
|
|
452
|
+
`脚本: ${typeof raw.isRunning === "boolean"
|
|
453
|
+
? raw.isRunning
|
|
454
|
+
? "运行中"
|
|
455
|
+
: "未运行"
|
|
456
|
+
: "未知"}`,
|
|
457
|
+
`总内存: ${formatRuntimeMetricText(memory.total, " MB")}`,
|
|
458
|
+
`可用: ${formatRuntimeMetricText(memory.available, " MB")}`,
|
|
459
|
+
`已用: ${formatRuntimeMetricText(memory.used, " MB")}`,
|
|
460
|
+
`占用: ${formatRuntimeMetricText(memory.usagePercentage, "%")}`,
|
|
461
|
+
].join(" | ");
|
|
462
|
+
}
|
|
399
463
|
/**
|
|
400
464
|
* 格式化单条 API 文档摘要
|
|
401
465
|
* @param language 文档语言
|