myagent-ai 1.5.1 → 1.5.2
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/install/install.ps1 +1 -1
- package/install/install.sh +1 -1
- package/package.json +1 -1
- package/setup.py +1 -1
- package/start.js +8 -4
- package/web/__pycache__/api_server.cpython-312.pyc +0 -0
- package/web/api_server.py +57 -16
package/install/install.ps1
CHANGED
package/install/install.sh
CHANGED
package/package.json
CHANGED
package/setup.py
CHANGED
|
@@ -9,7 +9,7 @@ from pathlib import Path
|
|
|
9
9
|
_version_path = Path(__file__).parent / "core" / "version.py"
|
|
10
10
|
_version_vars = {}
|
|
11
11
|
exec(_version_path.read_text(), _version_vars)
|
|
12
|
-
__version__ = _version_vars.get("BASE_VERSION", "1.5.
|
|
12
|
+
__version__ = _version_vars.get("BASE_VERSION", "1.5.2")
|
|
13
13
|
|
|
14
14
|
setup(
|
|
15
15
|
name="myagent",
|
package/start.js
CHANGED
|
@@ -239,8 +239,8 @@ function installDeps(venvPython, venvPip, pkgDir) {
|
|
|
239
239
|
let missing = [];
|
|
240
240
|
console.log(" \x1b[36m[*]\x1b[0m 检查依赖...");
|
|
241
241
|
|
|
242
|
-
//
|
|
243
|
-
const checkLimit = Math.min(allModules.length,
|
|
242
|
+
// 检查所有模块(不超过 30 个),托盘和 GUI 依赖也必须检测
|
|
243
|
+
const checkLimit = Math.min(allModules.length, 30);
|
|
244
244
|
for (let i = 0; i < checkLimit; i++) {
|
|
245
245
|
const mod = allModules[i];
|
|
246
246
|
try {
|
|
@@ -253,7 +253,7 @@ function installDeps(venvPython, venvPip, pkgDir) {
|
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
if (missing.length === 0) {
|
|
256
|
-
console.log(` \x1b[32m[✓]\x1b[0m ${checkLimit} 个依赖检查通过`);
|
|
256
|
+
console.log(` \x1b[32m[✓]\x1b[0m 全部 ${checkLimit} 个依赖检查通过`);
|
|
257
257
|
return;
|
|
258
258
|
}
|
|
259
259
|
|
|
@@ -277,8 +277,9 @@ function installDeps(venvPython, venvPip, pkgDir) {
|
|
|
277
277
|
});
|
|
278
278
|
console.log(" \x1b[32m[✓]\x1b[0m 依赖安装完成");
|
|
279
279
|
installed = true;
|
|
280
|
-
} catch (
|
|
280
|
+
} catch (err) {
|
|
281
281
|
console.log(" \x1b[33m[!]\x1b[0m requirements.txt 安装失败,尝试直接安装核心依赖...");
|
|
282
|
+
console.log(` \x1b[90m[i]\x1b[0m 错误: ${err.message}`);
|
|
282
283
|
}
|
|
283
284
|
}
|
|
284
285
|
|
|
@@ -293,6 +294,9 @@ function installDeps(venvPython, venvPip, pkgDir) {
|
|
|
293
294
|
} catch (_) {
|
|
294
295
|
console.error(" \x1b[31m[✗]\x1b[0m 依赖安装失败,请手动运行:");
|
|
295
296
|
console.error(` ${venvPython} -m pip install -r "${reqFile}"`);
|
|
297
|
+
console.error("");
|
|
298
|
+
console.error(" 或使用重新安装命令: myagent-ai reinstall");
|
|
299
|
+
console.error("");
|
|
296
300
|
}
|
|
297
301
|
}
|
|
298
302
|
}
|
|
Binary file
|
package/web/api_server.py
CHANGED
|
@@ -541,6 +541,10 @@ class ApiServer:
|
|
|
541
541
|
def _ensure_default_agent(self):
|
|
542
542
|
"""确保默认 agent 存在(名为「全权Agent」,目录名保持 default)"""
|
|
543
543
|
ad = self._agent_dir("default")
|
|
544
|
+
# 先尝试迁移(会自动修复损坏的 config.json)
|
|
545
|
+
if (ad / "config.json").exists():
|
|
546
|
+
self._migrate_agent_config("default", "全权Agent")
|
|
547
|
+
# 迁移后再次检查(损坏文件可能已被删除)
|
|
544
548
|
if not (ad / "config.json").exists():
|
|
545
549
|
ad.mkdir(parents=True, exist_ok=True)
|
|
546
550
|
now = datetime.datetime.now().isoformat()
|
|
@@ -566,20 +570,40 @@ class ApiServer:
|
|
|
566
570
|
if not (ad / fn).exists():
|
|
567
571
|
(ad / fn).write_text(default)
|
|
568
572
|
logger.info("已创建默认 Agent (全权Agent)")
|
|
569
|
-
else:
|
|
570
|
-
# 迁移: 确保旧 default agent 有新字段
|
|
571
|
-
self._migrate_agent_config("default", "全权Agent")
|
|
572
573
|
self._ensure_config_helper()
|
|
573
574
|
|
|
574
575
|
def _migrate_agent_config(self, path: str, intended_name: str = None):
|
|
575
|
-
"""为旧 agent config 添加缺失的 id, created_at, updated_at
|
|
576
|
+
"""为旧 agent config 添加缺失的 id, created_at, updated_at 字段;JSON 损坏则自动重建"""
|
|
576
577
|
cfg_file = self._agent_dir(path) / "config.json"
|
|
577
578
|
if not cfg_file.exists():
|
|
578
579
|
return
|
|
579
580
|
try:
|
|
580
581
|
cfg = json.loads(cfg_file.read_text())
|
|
581
582
|
except (json.JSONDecodeError, ValueError):
|
|
582
|
-
logger.warning(f"Agent config JSON
|
|
583
|
+
logger.warning(f"Agent config JSON 解析失败,自动删除重建: {path}")
|
|
584
|
+
try:
|
|
585
|
+
cfg_file.unlink()
|
|
586
|
+
except OSError:
|
|
587
|
+
pass
|
|
588
|
+
# 如果是 default 或配置助手,由 _ensure_default_agent / _ensure_config_helper 重建
|
|
589
|
+
if path in ("default", "配置助手", "p"):
|
|
590
|
+
return
|
|
591
|
+
# 其他 agent:创建一个最小 config
|
|
592
|
+
ad = self._agent_dir(path)
|
|
593
|
+
if ad.exists():
|
|
594
|
+
now = datetime.datetime.now().isoformat()
|
|
595
|
+
cfg = {
|
|
596
|
+
"id": uuid.uuid4().hex[:12],
|
|
597
|
+
"name": path,
|
|
598
|
+
"description": "",
|
|
599
|
+
"avatar_emoji": "🤖",
|
|
600
|
+
"execution_mode": "sandbox",
|
|
601
|
+
"enabled": True,
|
|
602
|
+
"created_at": now,
|
|
603
|
+
"updated_at": now,
|
|
604
|
+
}
|
|
605
|
+
cfg_file.write_text(json.dumps(cfg, indent=2, ensure_ascii=False))
|
|
606
|
+
logger.info(f"已重建 Agent 配置: {path}")
|
|
583
607
|
return
|
|
584
608
|
changed = False
|
|
585
609
|
now = datetime.datetime.now().isoformat()
|
|
@@ -602,6 +626,10 @@ class ApiServer:
|
|
|
602
626
|
def _ensure_config_helper(self):
|
|
603
627
|
"""确保系统级「配置助手」agent 存在(不可删除、不可改名、核心字段不可修改)"""
|
|
604
628
|
ad = self._agent_dir("配置助手")
|
|
629
|
+
# 先尝试迁移(会自动修复损坏的 config.json)
|
|
630
|
+
if (ad / "config.json").exists():
|
|
631
|
+
self._migrate_agent_config("配置助手")
|
|
632
|
+
# 迁移后再次检查(损坏文件可能已被删除)
|
|
605
633
|
if not (ad / "config.json").exists():
|
|
606
634
|
ad.mkdir(parents=True, exist_ok=True)
|
|
607
635
|
now = datetime.datetime.now().isoformat()
|
|
@@ -645,12 +673,15 @@ class ApiServer:
|
|
|
645
673
|
kb_dir.mkdir(parents=True, exist_ok=True)
|
|
646
674
|
target = kb_dir / "配置使用说明.md"
|
|
647
675
|
|
|
648
|
-
#
|
|
676
|
+
# 查找源文件
|
|
677
|
+
# __file__ = .../myagent-ai/web/api_server.py
|
|
678
|
+
# parent.parent = .../myagent-ai (包根目录,docs/ 在这里)
|
|
679
|
+
pkg_root = Path(__file__).resolve().parent.parent
|
|
649
680
|
source_candidates = [
|
|
650
|
-
|
|
651
|
-
|
|
681
|
+
pkg_root / "docs" / "配置使用说明.md",
|
|
682
|
+
pkg_root.parent / "docs" / "配置使用说明.md",
|
|
652
683
|
]
|
|
653
|
-
#
|
|
684
|
+
# npm 全局安装时也尝试通过 import 定位
|
|
654
685
|
try:
|
|
655
686
|
import myagent
|
|
656
687
|
pkg_dir = Path(myagent.__file__).resolve().parent
|
|
@@ -674,7 +705,7 @@ class ApiServer:
|
|
|
674
705
|
if hasattr(self, '_agent_rags') and "配置助手" in self._agent_rags:
|
|
675
706
|
self._agent_rags["配置助手"].build_index()
|
|
676
707
|
else:
|
|
677
|
-
logger.warning("未找到 配置使用说明.md
|
|
708
|
+
logger.warning(f"未找到 配置使用说明.md 源文件,已搜索: {[str(c) for c in source_candidates]}")
|
|
678
709
|
|
|
679
710
|
def _read_agent_config(self, path: str) -> dict | None:
|
|
680
711
|
"""读取 agent 配置"""
|
|
@@ -756,12 +787,22 @@ class ApiServer:
|
|
|
756
787
|
continue
|
|
757
788
|
agent_path = f"{prefix}{d.name}" if not prefix else f"{prefix}/{d.name}"
|
|
758
789
|
# 迁移: 为缺少 id/created_at/updated_at 的旧 agent 补全字段
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
790
|
+
# 跳过符号链接目录(如 p -> 配置助手),避免重复处理
|
|
791
|
+
if d.is_symlink():
|
|
792
|
+
try:
|
|
793
|
+
cfg = json.loads(cfg_file.read_text())
|
|
794
|
+
except (json.JSONDecodeError, ValueError):
|
|
795
|
+
continue
|
|
796
|
+
else:
|
|
797
|
+
self._migrate_agent_config(agent_path)
|
|
798
|
+
# 迁移可能删除了损坏的文件
|
|
799
|
+
if not cfg_file.exists():
|
|
800
|
+
continue
|
|
801
|
+
try:
|
|
802
|
+
cfg = json.loads(cfg_file.read_text())
|
|
803
|
+
except (json.JSONDecodeError, ValueError):
|
|
804
|
+
logger.warning(f"Agent config JSON 解析失败,跳过: {agent_path}")
|
|
805
|
+
continue
|
|
765
806
|
agent = {"path": agent_path, "name": d.name, **cfg}
|
|
766
807
|
agent["avatar_color"] = cfg.get("avatar_color") or _agent_color(d.name)
|
|
767
808
|
agent["depth"] = agent_path.count("/")
|