myagent-ai 1.15.75 → 1.15.77
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/package.json +1 -1
- package/start.js +33 -11
package/package.json
CHANGED
package/start.js
CHANGED
|
@@ -385,36 +385,58 @@ function cmdReinstall(pkgDir) {
|
|
|
385
385
|
}
|
|
386
386
|
|
|
387
387
|
function cmdUpdate(pkgDir) {
|
|
388
|
+
// 读取当前版本
|
|
389
|
+
let curVer = "";
|
|
390
|
+
try { curVer = JSON.parse(fs.readFileSync(path.join(pkgDir, "package.json"), "utf8")).version || ""; } catch (_) {}
|
|
391
|
+
|
|
388
392
|
console.log("");
|
|
389
|
-
console.log(
|
|
393
|
+
console.log(` [36mMyAgent 更新${curVer ? " v" + curVer : "到最新版"}[0m`);
|
|
390
394
|
console.log("");
|
|
391
395
|
|
|
392
|
-
// 1. npm
|
|
396
|
+
// 1. npm 升级全局包(--force 确保跳过缓存)
|
|
393
397
|
console.log(" 正在通过 npm 更新 myagent-ai ...");
|
|
394
398
|
try {
|
|
395
|
-
execFileSync("npm", ["install", "-g", PKG_NAME, "--prefer-online"], {
|
|
399
|
+
execFileSync("npm", ["install", "-g", PKG_NAME, "--prefer-online", "--force"], {
|
|
396
400
|
encoding: "utf8", stdio: "inherit", timeout: 120000,
|
|
397
401
|
});
|
|
398
402
|
} catch (e) {
|
|
399
|
-
console.error("
|
|
403
|
+
console.error("[31mnpm 更新失败,请尝试手动运行: npm install -g myagent-ai@latest --force[0m");
|
|
400
404
|
process.exit(1);
|
|
401
405
|
}
|
|
402
|
-
console.log(" \x1b[32m✓\x1b[0m npm 包已更新");
|
|
403
406
|
|
|
404
407
|
// 2. 重新定位 pkgDir(npm 更新后路径可能变化)
|
|
405
408
|
const newPkgDir = resolvePackageDir();
|
|
406
409
|
if (!fs.existsSync(path.join(newPkgDir, "main.py"))) {
|
|
407
|
-
console.error("
|
|
410
|
+
console.error("[31m更新后找不到 main.py,请重新安装: npm install -g myagent-ai@latest[0m");
|
|
408
411
|
process.exit(1);
|
|
409
412
|
}
|
|
410
413
|
|
|
411
|
-
let
|
|
412
|
-
try {
|
|
413
|
-
|
|
414
|
+
let newVer = "";
|
|
415
|
+
try { newVer = JSON.parse(fs.readFileSync(path.join(newPkgDir, "package.json"), "utf8")).version || ""; } catch (_) {}
|
|
416
|
+
|
|
417
|
+
// 3. 如果版本变了,用新的 start.js 重新执行自身,确保运行最新代码
|
|
418
|
+
if (curVer && newVer && curVer !== newVer) {
|
|
419
|
+
const newStartJs = path.join(newPkgDir, "start.js");
|
|
420
|
+
if (fs.existsSync(newStartJs)) {
|
|
421
|
+
console.log(` [33m已下载 v${newVer},正在切换到新版本...[0m`);
|
|
422
|
+
console.log("");
|
|
423
|
+
const { execSync } = require("child_process");
|
|
424
|
+
execSync(process.execPath + ' "' + newStartJs + '" update', {
|
|
425
|
+
stdio: "inherit", windowsHide: true, timeout: 30000,
|
|
426
|
+
});
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
markDepsInstalled(newVer);
|
|
414
432
|
|
|
415
433
|
console.log("");
|
|
416
|
-
|
|
417
|
-
|
|
434
|
+
if (newVer) {
|
|
435
|
+
console.log(` [32m✓ 已是最新版 v${newVer}[0m`);
|
|
436
|
+
} else {
|
|
437
|
+
console.log(` [32m✓ 更新完成[0m`);
|
|
438
|
+
}
|
|
439
|
+
console.log(` 运行 [36mmyagent-ai web[0m 启动`);
|
|
418
440
|
console.log("");
|
|
419
441
|
}
|
|
420
442
|
|