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