lingshu-skill 5.9.0 → 5.11.0
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/CHANGELOG.md +44 -0
- package/README.md +41 -3
- package/SKILL.md +2 -1
- package/assets/panel.html +655 -563
- package/docs//350/277/233/345/261/225/344/270/216/345/276/205/345/212/236.md +20 -0
- package/package.json +1 -1
- package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +10 -10
- package/scripts/astrbot_plugin_lingshu/engine/CHANGELOG.md +44 -0
- package/scripts/astrbot_plugin_lingshu/engine/README.md +41 -3
- package/scripts/astrbot_plugin_lingshu/engine/SKILL.md +2 -1
- package/scripts/astrbot_plugin_lingshu/engine/assets/panel.html +655 -563
- package/scripts/astrbot_plugin_lingshu/engine/scripts/cli.py +9 -3
- package/scripts/astrbot_plugin_lingshu/engine/scripts/core.py +2 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/growth.py +4951 -4753
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_server.py +39 -7
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_settings.py +3 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_update.py +38 -9
- package/scripts/cli.py +9 -3
- package/scripts/core.py +2 -0
- package/scripts/growth.py +4951 -4753
- package/scripts/panel_server.py +39 -7
- package/scripts/panel_settings.py +3 -0
- package/scripts/panel_update.py +38 -9
|
@@ -737,17 +737,34 @@ class Handler(BaseHTTPRequestHandler):
|
|
|
737
737
|
qs = parse_qs(url.query)
|
|
738
738
|
auto = (qs.get("auto") or ["0"])[0] in ("1", "true", "yes")
|
|
739
739
|
refresh = (qs.get("refresh") or ["0"])[0] in ("1", "true", "yes")
|
|
740
|
+
src_pref = (qs.get("source") or [""])[0].strip().lower()
|
|
741
|
+
if src_pref not in ("npm", "git"):
|
|
742
|
+
src_pref = ""
|
|
740
743
|
res = growth.update_check("lingshu", force_pull=refresh, auto=auto)
|
|
741
744
|
# 透出源类型(dev/remote/installed/none)与源目标路径,供前端确认框展示。
|
|
742
745
|
# 注意:这里不能再 force_pull=refresh——update_check 刚拉过一遍远程并写了
|
|
743
746
|
# 缓存,再来一遍等于把整条 Gitee/GitHub 拉取链路跑两次,手动检查必然超时。
|
|
744
747
|
if isinstance(res, dict) and res.get("cached") is not False:
|
|
745
748
|
try:
|
|
746
|
-
src, kind = growth.resolve_source("lingshu", force_pull=False
|
|
749
|
+
src, kind = growth.resolve_source("lingshu", force_pull=False,
|
|
750
|
+
prefer=(src_pref or None))
|
|
747
751
|
res["source_kind"] = kind
|
|
752
|
+
res["source"] = kind
|
|
748
753
|
res["target_path"] = str(src)
|
|
749
|
-
except Exception:
|
|
754
|
+
except Exception as exc: # noqa: BLE001
|
|
750
755
|
res.setdefault("source_kind", res.get("source", "none"))
|
|
756
|
+
res["source_error"] = str(exc)[:200]
|
|
757
|
+
# 手动检查时附带 npm 版本信息(走缓存,不打二次网络):前端能显示
|
|
758
|
+
# "npm 最新 vX(~N KB)",让用户知道这个下载方式可用、多大。
|
|
759
|
+
if isinstance(res, dict) and refresh and not auto:
|
|
760
|
+
try:
|
|
761
|
+
nm = growth.npm_latest(force=False)
|
|
762
|
+
if nm.get("ok"):
|
|
763
|
+
res["npm"] = {"version": nm.get("version"),
|
|
764
|
+
"unpacked": nm.get("unpacked"),
|
|
765
|
+
"cached": bool(nm.get("cached"))}
|
|
766
|
+
except Exception:
|
|
767
|
+
pass
|
|
751
768
|
self._json(res)
|
|
752
769
|
return
|
|
753
770
|
if path == "/api/workspace":
|
|
@@ -1634,14 +1651,29 @@ def _api_skill(self, path, data):
|
|
|
1634
1651
|
data.get("append"), data.get("description"))
|
|
1635
1652
|
self._json({"ok": True, "skill": res, "workspace": workspace()})
|
|
1636
1653
|
elif act == "install":
|
|
1637
|
-
#
|
|
1638
|
-
|
|
1654
|
+
# 面板安装忽略前端传的 from_dir:本地 CLI 才能指外部目录,防远程乱指。
|
|
1655
|
+
# 但允许传**下载源枚举**(npm/git):目录由服务端自己 resolve,客户端拿不到路径控制权。
|
|
1656
|
+
_name = data.get("name", "")
|
|
1657
|
+
_src_pref = str(data.get("source") or "").strip().lower()
|
|
1658
|
+
_from = None
|
|
1659
|
+
if _src_pref in ("npm", "git") and _name:
|
|
1660
|
+
try:
|
|
1661
|
+
_dir, _kind = growth.resolve_source(_name, force_pull=True,
|
|
1662
|
+
prefer=_src_pref)
|
|
1663
|
+
_from = str(_dir)
|
|
1664
|
+
except KeyError as exc:
|
|
1665
|
+
self._json({"error": f"{_src_pref} 下载源不可用:{exc}"}, 502)
|
|
1666
|
+
return
|
|
1667
|
+
res = growth.install_skill(_name,
|
|
1639
1668
|
bool(data.get("force")),
|
|
1640
|
-
|
|
1669
|
+
_from,
|
|
1641
1670
|
accept_risk=bool(data.get("yes")))
|
|
1671
|
+
if isinstance(res, dict):
|
|
1672
|
+
res.setdefault("source", _src_pref or "auto")
|
|
1642
1673
|
# 面板触发的更新/安装要留痕(特别是本体 lingshu):事后能查谁在何时更新到什么状态
|
|
1643
|
-
brain.log_event("panel", f"安装/更新技能 {
|
|
1644
|
-
f"(force={bool(data.get('force'))})
|
|
1674
|
+
brain.log_event("panel", f"安装/更新技能 {_name} "
|
|
1675
|
+
f"(源={_src_pref or 'auto'}, force={bool(data.get('force'))}) "
|
|
1676
|
+
f"→ {res.get('state')}")
|
|
1645
1677
|
self._json({"ok": True, "result": res, "workspace": workspace()})
|
|
1646
1678
|
return
|
|
1647
1679
|
elif act == "uninstall":
|
|
@@ -76,6 +76,9 @@ CONFIG_SCHEMA: list[dict[str, Any]] = [
|
|
|
76
76
|
"hint": "送进 rerank 的候选条数,越大越准也越慢"},
|
|
77
77
|
|
|
78
78
|
# —— 面板与宿主 ——
|
|
79
|
+
{"key": "update_source", "group": "自动更新与备份", "label": "更新下载源",
|
|
80
|
+
"kind": "enum", "options": ["auto", "npm", "git"],
|
|
81
|
+
"hint": "auto=npm 优先(失败退回 Gitee/GitHub);npm=只走 npm 官方包;git=只走 Gitee/GitHub"},
|
|
79
82
|
{"key": "panel_idle_minutes", "group": "面板与宿主", "label": "空闲自动退出(分钟)",
|
|
80
83
|
"kind": "int", "min": 0, "max": 1440, "step": 5,
|
|
81
84
|
"hint": "关掉网页后,多少分钟没请求就自动退出服务(默认 1);0=永不退出(需重启面板生效)"},
|
|
@@ -27,24 +27,51 @@ def enabled() -> bool:
|
|
|
27
27
|
return bool(_cfg().get("auto_update"))
|
|
28
28
|
|
|
29
29
|
|
|
30
|
-
def
|
|
31
|
-
"""
|
|
30
|
+
def _normalize(res: dict) -> dict:
|
|
31
|
+
"""把 growth.update_check 的字段名补成调用方好用的别名,**不改原字段**。
|
|
32
|
+
|
|
33
|
+
历史坑:run() 判断的是 `update_available`,而 update_check 返回的是 `outdated`,
|
|
34
|
+
于是自动更新永远走"已是最新"分支——功能等于没接上。
|
|
35
|
+
"""
|
|
36
|
+
if not isinstance(res, dict):
|
|
37
|
+
return res
|
|
38
|
+
if "update_available" not in res:
|
|
39
|
+
res["update_available"] = bool(res.get("outdated"))
|
|
40
|
+
res.setdefault("current", res.get("installed_version"))
|
|
41
|
+
res.setdefault("latest", res.get("source_version") or res.get("version"))
|
|
42
|
+
return res
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def check(force_pull: bool = False, source: str | None = None) -> dict:
|
|
46
|
+
"""查有没有新版本(只读)。`source` 可强制 "npm" / "git"。"""
|
|
32
47
|
import growth
|
|
33
48
|
try:
|
|
34
|
-
|
|
49
|
+
if source:
|
|
50
|
+
# 强制指定源时先把它解析出来(顺带把"能不能拿到"这件事暴露给调用方)
|
|
51
|
+
src, kind = growth.resolve_source("lingshu", force_pull=force_pull,
|
|
52
|
+
prefer=source)
|
|
53
|
+
res = growth.update_check("lingshu", force_pull=force_pull,
|
|
54
|
+
prefer=source)
|
|
55
|
+
if isinstance(res, dict):
|
|
56
|
+
res["source"] = kind
|
|
57
|
+
res["source_kind"] = kind
|
|
58
|
+
res["target_path"] = str(src)
|
|
59
|
+
return _normalize(res)
|
|
60
|
+
return _normalize(growth.update_check("lingshu", force_pull=force_pull,
|
|
61
|
+
prefer=source))
|
|
35
62
|
except Exception as exc: # noqa: BLE001
|
|
36
63
|
core.log_event("update", f"检查更新失败:{exc}", level="warn")
|
|
37
64
|
return {"ok": False, "error": str(exc)}
|
|
38
65
|
|
|
39
66
|
|
|
40
|
-
def run(force: bool = False) -> dict:
|
|
41
|
-
"""
|
|
67
|
+
def run(force: bool = False, source: str | None = None) -> dict:
|
|
68
|
+
"""执行一次自动更新(含更新前备份)。`source` 可强制 "npm" / "git"。"""
|
|
42
69
|
if core.READONLY:
|
|
43
70
|
return {"ok": False, "reason": "记忆库只读,跳过自动更新"}
|
|
44
71
|
if not force and not enabled():
|
|
45
72
|
return {"ok": False, "skipped": True, "reason": "auto_update 未开启"}
|
|
46
73
|
|
|
47
|
-
chk = check(force_pull=True)
|
|
74
|
+
chk = check(force_pull=True, source=source)
|
|
48
75
|
if not chk or not chk.get("update_available"):
|
|
49
76
|
return {"ok": True, "skipped": True,
|
|
50
77
|
"reason": "已是最新", "current": chk.get("current"),
|
|
@@ -67,15 +94,17 @@ def run(force: bool = False) -> dict:
|
|
|
67
94
|
# ② 原子更新
|
|
68
95
|
try:
|
|
69
96
|
import growth
|
|
70
|
-
src, kind = growth.resolve_source("lingshu", force_pull=False
|
|
97
|
+
src, kind = growth.resolve_source("lingshu", force_pull=False,
|
|
98
|
+
prefer=source)
|
|
71
99
|
res = growth.install_skill("lingshu", force=True, from_dir=str(src))
|
|
72
100
|
except Exception as exc: # noqa: BLE001
|
|
73
101
|
core.log_event("update", f"自动更新失败:{exc}", level="error")
|
|
74
102
|
return {"ok": False, "reason": f"更新失败(已回滚):{exc}", "backup": bak}
|
|
75
103
|
|
|
76
|
-
core.log_event("update", f"
|
|
77
|
-
f"
|
|
104
|
+
core.log_event("update", f"自动更新完成(来源 {chk.get('source') or 'auto'}):"
|
|
105
|
+
f"{chk.get('current')} → {chk.get('latest')};更新前备份 {bak}")
|
|
78
106
|
return {"ok": True, "updated": True, "backup": bak,
|
|
107
|
+
"source": chk.get("source") or "auto",
|
|
79
108
|
"from": chk.get("current"), "to": chk.get("latest"),
|
|
80
109
|
"detail": res if isinstance(res, dict) else str(res),
|
|
81
110
|
"at": int(time.time())}
|
package/scripts/cli.py
CHANGED
|
@@ -1608,6 +1608,9 @@ def _main(argv=None) -> int:
|
|
|
1608
1608
|
p_au.add_argument("--check", action="store_true", help="只检查有没有新版本,不安装")
|
|
1609
1609
|
p_au.add_argument("--force", action="store_true", help="忽略 auto_update 开关强制执行一次")
|
|
1610
1610
|
p_au.add_argument("--json", action="store_true")
|
|
1611
|
+
p_au.add_argument("--source", choices=["auto", "npm", "git"], default="auto",
|
|
1612
|
+
help="下载源:auto(npm 优先,失败退回 Gitee/GitHub)/ npm(只走 npm)/ "
|
|
1613
|
+
"git(只走 Gitee/GitHub)")
|
|
1611
1614
|
|
|
1612
1615
|
# 附录 C P2 收尾:触发 + 落盘 + 回滚
|
|
1613
1616
|
p_ss = sub.add_parser("session-summary",
|
|
@@ -2655,15 +2658,17 @@ def _main(argv=None) -> int:
|
|
|
2655
2658
|
|
|
2656
2659
|
if args.cmd == "auto-update":
|
|
2657
2660
|
import panel_update as _pu
|
|
2661
|
+
_src = None if args.source == "auto" else args.source
|
|
2658
2662
|
if args.check:
|
|
2659
|
-
res = _pu.check(force_pull=True)
|
|
2663
|
+
res = _pu.check(force_pull=True, source=_src)
|
|
2660
2664
|
if args.json:
|
|
2661
2665
|
print(json.dumps(res, ensure_ascii=False, indent=2))
|
|
2662
2666
|
return 0
|
|
2663
2667
|
print(f"当前 {res.get('current')} / 最新 {res.get('latest')} "
|
|
2668
|
+
f"(来源 {res.get('source') or 'auto'})"
|
|
2664
2669
|
f"→ {'有新版可更新' if res.get('update_available') else '已是最新'}")
|
|
2665
2670
|
return 0
|
|
2666
|
-
res = _pu.run(force=args.force)
|
|
2671
|
+
res = _pu.run(force=args.force, source=_src)
|
|
2667
2672
|
if args.json:
|
|
2668
2673
|
print(json.dumps(res, ensure_ascii=False, indent=2))
|
|
2669
2674
|
return 0 if res.get("ok") else 1
|
|
@@ -2671,7 +2676,8 @@ def _main(argv=None) -> int:
|
|
|
2671
2676
|
print(f"跳过:{res.get('reason')}")
|
|
2672
2677
|
return 0
|
|
2673
2678
|
if res.get("ok"):
|
|
2674
|
-
print(f"
|
|
2679
|
+
print(f"已更新(来源 {res.get('source') or 'auto'}):"
|
|
2680
|
+
f"{res.get('from')} → {res.get('to')};更新前备份 {res.get('backup')}")
|
|
2675
2681
|
return 0
|
|
2676
2682
|
print(f"[错误] {res.get('reason')}", file=sys.stderr)
|
|
2677
2683
|
return 1
|
package/scripts/core.py
CHANGED
|
@@ -340,6 +340,8 @@ DEFAULT_CONFIG = {
|
|
|
340
340
|
# 面板空闲多少分钟自动退出(0 = 永不)。页面挂着长轮询保活(不受后台定时器节流影响),
|
|
341
341
|
# 关掉网页后连接断开 → 到点自退。默认 1 分钟:关掉尽快回收,不占后台。
|
|
342
342
|
"panel_idle_minutes": 1,
|
|
343
|
+
# 更新下载源:auto=npm 优先(失败退回 Gitee/GitHub)/ npm=只走 npm / git=只走 Gitee/GitHub
|
|
344
|
+
"update_source": "auto",
|
|
343
345
|
"auto_update_interval_hours": 24,
|
|
344
346
|
"session_state_cache": False,
|
|
345
347
|
"session_state_ttl": 300,
|