ms-vite-plugin 1.1.11 → 1.1.12
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 +2 -101
- package/package.json +1 -1
package/dist/mcp/tools.js
CHANGED
|
@@ -348,48 +348,6 @@ function registerRuntimeTools(server) {
|
|
|
348
348
|
],
|
|
349
349
|
};
|
|
350
350
|
});
|
|
351
|
-
/**
|
|
352
|
-
* 格式化运行期日志结果(供 run/run_ui 直接回传)
|
|
353
|
-
* @param ip 设备 IP
|
|
354
|
-
* @param port 设备端口
|
|
355
|
-
* @param durationSeconds 监听秒数
|
|
356
|
-
* @param result 日志监听结果
|
|
357
|
-
* @returns 可拼接到 tool 响应的文本
|
|
358
|
-
* @example
|
|
359
|
-
* const text = formatRunLogSection("192.168.1.10", 9800, 10, result)
|
|
360
|
-
*/
|
|
361
|
-
function formatRunLogSection(ip, port, result) {
|
|
362
|
-
const logsPreview = result.logs
|
|
363
|
-
.slice(-20)
|
|
364
|
-
.map((log) => `[${log.timestamp}] [${log.level.toUpperCase()}] ${log.message}`)
|
|
365
|
-
.join("\n");
|
|
366
|
-
return [
|
|
367
|
-
`运行日志来源: ${ip}:${port}`,
|
|
368
|
-
`结束原因: ${result.stopReason},日志: ${result.logs.length} 条,runtime_status: ${result.runtimeStatus.length} 条`,
|
|
369
|
-
"最新日志(最多展示最后20条):",
|
|
370
|
-
logsPreview || "无日志",
|
|
371
|
-
].join("\n");
|
|
372
|
-
}
|
|
373
|
-
/**
|
|
374
|
-
* 启动持续日志监听(后台,不阻塞当前 tool 返回)
|
|
375
|
-
* @param ip 设备 IP
|
|
376
|
-
* @param port 设备端口
|
|
377
|
-
* @param maxLogs 日志环形缓冲上限
|
|
378
|
-
* @returns 返回提示文本
|
|
379
|
-
* @example
|
|
380
|
-
* const tip = startBackgroundContinuousLogWatch("192.168.1.10", 9800, 300)
|
|
381
|
-
*/
|
|
382
|
-
function startBackgroundContinuousLogWatch(ip, port, maxLogs) {
|
|
383
|
-
void (0, project_1.watchDeviceLogsBySse)(ip, port, 0, maxLogs)
|
|
384
|
-
.then((result) => {
|
|
385
|
-
console.log(`[mcp] continuous logs ${ip}:${port} ended, reason=${result.stopReason}, logs=${result.logs.length}, runtime_status=${result.runtimeStatus.length}`);
|
|
386
|
-
})
|
|
387
|
-
.catch((error) => {
|
|
388
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
389
|
-
console.warn(`[mcp] continuous logs ${ip}:${port} failed: ${message}`);
|
|
390
|
-
});
|
|
391
|
-
return `已切换为持续日志监听: ${ip}:${port}(直到连接断开,max ${maxLogs})`;
|
|
392
|
-
}
|
|
393
351
|
/**
|
|
394
352
|
* 解析运行目标:
|
|
395
353
|
* - 显式 transport=ws: 强制走 ws
|
|
@@ -777,49 +735,9 @@ function registerRuntimeTools(server) {
|
|
|
777
735
|
.min(1)
|
|
778
736
|
.optional()
|
|
779
737
|
.describe("可选工作目录;不传时使用 set_workspace 记忆值"),
|
|
780
|
-
watchLogs: z
|
|
781
|
-
.boolean()
|
|
782
|
-
.optional()
|
|
783
|
-
.default(false)
|
|
784
|
-
.describe("是否在运行前启动日志监听,默认 false"),
|
|
785
|
-
logMode: z
|
|
786
|
-
.enum(["single", "continuous"])
|
|
787
|
-
.optional()
|
|
788
|
-
.default("single")
|
|
789
|
-
.describe("日志模式:single=按 runtime_status 收敛,continuous=持续监听"),
|
|
790
|
-
logMaxLogs: z
|
|
791
|
-
.number()
|
|
792
|
-
.int()
|
|
793
|
-
.min(10)
|
|
794
|
-
.max(5000)
|
|
795
|
-
.optional()
|
|
796
|
-
.default(300)
|
|
797
|
-
.describe("日志最大收集条数,默认 300"),
|
|
798
738
|
},
|
|
799
|
-
}, async ({ transport, ip, port, wsPort, wsWaitMs, workspacePath
|
|
739
|
+
}, async ({ transport, ip, port, wsPort, wsWaitMs, workspacePath }) => {
|
|
800
740
|
const workspace = await ensureWorkspacePath(workspacePath);
|
|
801
|
-
let logPromise;
|
|
802
|
-
let logDeviceIp = "";
|
|
803
|
-
let logDevicePort = 0;
|
|
804
|
-
let logSetupWarning = "";
|
|
805
|
-
let logModeNotice = "";
|
|
806
|
-
if (watchLogs) {
|
|
807
|
-
try {
|
|
808
|
-
const logDevice = await (0, device_config_1.resolveDeviceConfig)(ip, port);
|
|
809
|
-
// 先挂监听,再执行 run,确保拿到启动期实时日志
|
|
810
|
-
logDeviceIp = logDevice.ip;
|
|
811
|
-
logDevicePort = logDevice.port;
|
|
812
|
-
if (logMode === "continuous") {
|
|
813
|
-
logModeNotice = startBackgroundContinuousLogWatch(logDevice.ip, logDevice.port, logMaxLogs);
|
|
814
|
-
}
|
|
815
|
-
else {
|
|
816
|
-
logPromise = (0, project_1.watchDeviceLogsBySse)(logDevice.ip, logDevice.port, 0, logMaxLogs, true, true);
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
catch (error) {
|
|
820
|
-
logSetupWarning = `日志监听未启动: ${error instanceof Error ? error.message : String(error)}`;
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
741
|
const target = await resolvePreferredRuntimeTarget({
|
|
824
742
|
transport,
|
|
825
743
|
ip,
|
|
@@ -840,28 +758,11 @@ function registerRuntimeTools(server) {
|
|
|
840
758
|
transport: "http",
|
|
841
759
|
workspacePath: workspace,
|
|
842
760
|
});
|
|
843
|
-
let logSection = "";
|
|
844
|
-
if (logPromise) {
|
|
845
|
-
const result = await logPromise;
|
|
846
|
-
const sections = [
|
|
847
|
-
formatRunLogSection(logDeviceIp, logDevicePort, result),
|
|
848
|
-
];
|
|
849
|
-
if (result.stopReason === "runtime_continuous") {
|
|
850
|
-
sections.push(startBackgroundContinuousLogWatch(logDeviceIp, logDevicePort, logMaxLogs));
|
|
851
|
-
}
|
|
852
|
-
logSection = `\n\n${sections.join("\n")}`;
|
|
853
|
-
}
|
|
854
|
-
else if (logModeNotice) {
|
|
855
|
-
logSection = `\n\n${logModeNotice}`;
|
|
856
|
-
}
|
|
857
|
-
else if (logSetupWarning) {
|
|
858
|
-
logSection = `\n\n${logSetupWarning}`;
|
|
859
|
-
}
|
|
860
761
|
return {
|
|
861
762
|
content: [
|
|
862
763
|
{
|
|
863
764
|
type: "text",
|
|
864
|
-
text: `运行请求已发送到 ${target.label}
|
|
765
|
+
text: `运行请求已发送到 ${target.label}`,
|
|
865
766
|
},
|
|
866
767
|
],
|
|
867
768
|
};
|