lingshu-skill 5.29.0 → 5.31.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 +168 -0
- package/README.md +1 -1
- package/SKILL-lite.md +1 -1
- package/SKILL-tiny.md +1 -1
- package/SKILL.md +341 -405
- package/assets/panel.html +532 -19
- package/cordis-plugin/lingshu-cron/plugin.js +195 -29
- package/docs//344/275/277/347/224/250/346/214/207/345/215/227.md +229 -0
- package/docs//345/256/241/346/240/270/346/224/271/350/277/233/345/276/205/345/212/236.md +134 -43
- package/docs//345/276/205/345/212/236/346/250/241/346/235/277.md +140 -0
- package/package.json +1 -1
- package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +20 -17
- package/scripts/astrbot_plugin_lingshu/engine/CHANGELOG.md +168 -0
- package/scripts/astrbot_plugin_lingshu/engine/README.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL-lite.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL-tiny.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL.md +341 -405
- package/scripts/astrbot_plugin_lingshu/engine/assets/panel.html +532 -19
- package/scripts/astrbot_plugin_lingshu/engine/scripts/cli.py +47 -18
- package/scripts/astrbot_plugin_lingshu/engine/scripts/core.py +32 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/dream.py +22 -7
- package/scripts/astrbot_plugin_lingshu/engine/scripts/emotion.py +14 -6
- package/scripts/astrbot_plugin_lingshu/engine/scripts/growth.py +27 -5
- package/scripts/astrbot_plugin_lingshu/engine/scripts/mem_dialogue.py +15 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/memory.py +641 -61
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_icon.py +220 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_launcher.py +114 -10
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_server.py +225 -72
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_shortcut.py +330 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_splash.py +181 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/persona.py +31 -11
- package/scripts/astrbot_plugin_lingshu/engine/scripts/safety_net.py +45 -9
- package/scripts/cli.py +47 -18
- package/scripts/core.py +32 -0
- package/scripts/dream.py +22 -7
- package/scripts/emotion.py +14 -6
- package/scripts/growth.py +27 -5
- package/scripts/mem_dialogue.py +15 -0
- package/scripts/memory.py +641 -61
- package/scripts/panel_icon.py +220 -0
- package/scripts/panel_launcher.py +114 -10
- package/scripts/panel_server.py +225 -72
- package/scripts/panel_shortcut.py +330 -0
- package/scripts/panel_splash.py +181 -0
- package/scripts/persona.py +31 -11
- package/scripts/safety_net.py +45 -9
|
@@ -65,6 +65,10 @@ _WRITE_ENDPOINTS = {
|
|
|
65
65
|
"/api/extensions/ollama/enable", "/api/extensions/ollama/setup",
|
|
66
66
|
# 数据目录迁移:写指针文件 + 复制数据(迁移目标在数据目录之外,单独放行只读门控)
|
|
67
67
|
"/api/home/migrate",
|
|
68
|
+
# 面板快捷方式的全局热键:写桌面 .lnk 的 Hotkey 字段(在数据目录之外,单独放行)
|
|
69
|
+
"/api/panel-shortcut",
|
|
70
|
+
# 自定义快捷方式图标:生成 .ico + 写 .lnk 的 IconLocation(同样在数据目录之外)
|
|
71
|
+
"/api/panel-icon",
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
# 本机随机 token:页面加载时注入,之后每个 API 请求都要带上。
|
|
@@ -270,9 +274,13 @@ def _doctor_history(days: int = 30) -> list:
|
|
|
270
274
|
date_str = datetime.fromtimestamp(ts, tz=timezone(timedelta(hours=8))).strftime("%m-%d")
|
|
271
275
|
if date_str not in by_day:
|
|
272
276
|
by_day[date_str] = {"date": date_str, "passes": 0, "warns": 0, "fails": 0}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
277
|
+
# 字段名以 doctor-history 写入端为准(pass/warn/fail);旧记录用
|
|
278
|
+
# passes/warns/fails,两者都认,避免历史数据整段消失。
|
|
279
|
+
# 原来只读 passes/warns/fails,而 growth.record_doctor_run 写的是
|
|
280
|
+
# pass/warn/fail → 那一半记录恒贡献 0,折线图永远平。
|
|
281
|
+
by_day[date_str]["passes"] += row.get("pass", row.get("passes", 0)) or 0
|
|
282
|
+
by_day[date_str]["warns"] += row.get("warn", row.get("warns", 0)) or 0
|
|
283
|
+
by_day[date_str]["fails"] += row.get("fail", row.get("fails", 0)) or 0
|
|
276
284
|
out = []
|
|
277
285
|
for d in sorted(by_day):
|
|
278
286
|
r = by_day[d]
|
|
@@ -282,46 +290,33 @@ def _doctor_history(days: int = 30) -> list:
|
|
|
282
290
|
|
|
283
291
|
|
|
284
292
|
def _health_score() -> int:
|
|
285
|
-
"""灵枢健康度:0-100,按最近 7 天 doctor FAIL/WARN + failures.jsonl 条数加权扣分。
|
|
286
293
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
294
|
+
"""灵枢健康度:0-100。**委托给 growth.health_score(),不在这里另算一套。**
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
原来这里有自己的公式(100 - fails*10 - warns*3 - fbcnt),而 growth.health_score
|
|
299
|
+
|
|
300
|
+
用的是 100 - fail*10 - warn*3 - failures_7d//5 → 面板 footer 与 stage/doctor 对
|
|
301
|
+
|
|
302
|
+
同一份数据给出两个不同分数,被吞异常越多差得越大。同一指标只能有一个口径。
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
历史记录字段名也一并由 growth 侧统一(pass/warn/fail),它自己会取最近一次体检。
|
|
307
|
+
|
|
292
308
|
"""
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
except json.JSONDecodeError:
|
|
305
|
-
continue
|
|
306
|
-
if row.get("ts", 0) < cutoff:
|
|
307
|
-
continue
|
|
308
|
-
fails += row.get("fails", 0)
|
|
309
|
-
warns += row.get("warns", 0)
|
|
310
|
-
# failures.jsonl 条数
|
|
311
|
-
fb = brain.HOME / "failures.jsonl"
|
|
312
|
-
fbcnt = 0
|
|
313
|
-
if fb.exists():
|
|
314
|
-
for line in fb.read_text(encoding="utf-8").splitlines():
|
|
315
|
-
if not line.strip():
|
|
316
|
-
continue
|
|
317
|
-
try:
|
|
318
|
-
row = json.loads(line)
|
|
319
|
-
except json.JSONDecodeError:
|
|
320
|
-
continue
|
|
321
|
-
if row.get("ts", 0) >= cutoff:
|
|
322
|
-
fbcnt += 1
|
|
323
|
-
score = max(0, 100 - fails * 10 - warns * 3 - fbcnt)
|
|
324
|
-
return score
|
|
309
|
+
|
|
310
|
+
try:
|
|
311
|
+
|
|
312
|
+
import growth as _growth
|
|
313
|
+
|
|
314
|
+
return int(_growth.health_score().get("score", 100))
|
|
315
|
+
|
|
316
|
+
except Exception:
|
|
317
|
+
|
|
318
|
+
return 100
|
|
319
|
+
|
|
325
320
|
|
|
326
321
|
|
|
327
322
|
def _created_key(m: dict):
|
|
@@ -551,6 +546,19 @@ def _migrate_home(target_raw: str) -> dict:
|
|
|
551
546
|
raise ValueError("目标目录不能为空")
|
|
552
547
|
if target == brain.HOME.resolve():
|
|
553
548
|
raise ValueError("目标目录与当前数据目录相同")
|
|
549
|
+
# ★ 目标不能落在数据目录**内部**(审计 panel_server.py:559):
|
|
550
|
+
# `copytree(HOME, target)` 时目标若在 HOME 底下,copytree 边复制边把刚创建的
|
|
551
|
+
# 目标目录自己也扫进去 → 递归膨胀,或中途 OSError 留下一份半截副本,
|
|
552
|
+
# 而且此时指针文件还没写,用户会得到一个"看起来迁好了、其实不完整"的目录。
|
|
553
|
+
# CLI 的 `home move` 有这道检查(relative_to 直接拒),这里漏了。
|
|
554
|
+
try:
|
|
555
|
+
target.relative_to(brain.HOME.resolve())
|
|
556
|
+
except ValueError:
|
|
557
|
+
pass # 不在内部,正常
|
|
558
|
+
else:
|
|
559
|
+
raise ValueError(
|
|
560
|
+
"目标目录在数据目录内部——复制时会把目标自己也扫进去(递归膨胀)。"
|
|
561
|
+
f"请选数据目录之外的路径(当前数据目录:{brain.HOME})")
|
|
554
562
|
if target.exists() and any(target.iterdir()):
|
|
555
563
|
raise ValueError("目标目录已存在且非空——请选一个空目录(或先手动清理)")
|
|
556
564
|
# 计划写指针的位置必须可写:指针文件永远在默认位置 ~/.brain-memory/ 下
|
|
@@ -909,7 +917,26 @@ class Handler(BaseHTTPRequestHandler):
|
|
|
909
917
|
return
|
|
910
918
|
if path == "/api/graph":
|
|
911
919
|
limit = _int_param(url, "limit", 300, 10, 800)
|
|
912
|
-
|
|
920
|
+
# v3.48 联想图密度闸门:把"元数据标签不算关联""单节点边数上限"
|
|
921
|
+
# "孤立记忆是否入图"三个开关暴露出来,面板可调、也可用它自查边爆炸。
|
|
922
|
+
qs = parse_qs(url.query)
|
|
923
|
+
def _flag(name: str, default: bool) -> bool:
|
|
924
|
+
v = (qs.get(name) or [""])[0].strip().lower()
|
|
925
|
+
if not v:
|
|
926
|
+
return default
|
|
927
|
+
return v not in ("0", "false", "no", "off")
|
|
928
|
+
def _num(name: str, default):
|
|
929
|
+
v = (qs.get(name) or [""])[0].strip()
|
|
930
|
+
try:
|
|
931
|
+
return float(v)
|
|
932
|
+
except (TypeError, ValueError):
|
|
933
|
+
return default
|
|
934
|
+
self._json(brain.assoc_graph(
|
|
935
|
+
limit,
|
|
936
|
+
generic_ratio=_num("generic_ratio", None),
|
|
937
|
+
max_degree=_num("max_degree", None),
|
|
938
|
+
hide_isolated=_flag("hide_isolated", True),
|
|
939
|
+
))
|
|
913
940
|
return
|
|
914
941
|
if path == "/api/diagnostics":
|
|
915
942
|
# 自诊断:死链 / 冲突未裁决 / 数据膨胀 / 淡忘可逆状态 / 来源归属完整率
|
|
@@ -919,6 +946,43 @@ class Handler(BaseHTTPRequestHandler):
|
|
|
919
946
|
# 数据目录信息:当前位置、是否指针生效、默认位置、当前库体积(面板设置卡片用)
|
|
920
947
|
self._json(_home_info())
|
|
921
948
|
return
|
|
949
|
+
if path == "/api/panel-icon":
|
|
950
|
+
# 图标状态:当前 IconLocation、是否自定义、预览(PNG data URL)
|
|
951
|
+
try:
|
|
952
|
+
import panel_icon, panel_shortcut
|
|
953
|
+
sc = panel_shortcut.read_shortcut()
|
|
954
|
+
cur = str(sc.get("icon") or "")
|
|
955
|
+
icon_path = cur.rsplit(",", 1)[0] if cur else ""
|
|
956
|
+
dflt = panel_icon.default_icon()
|
|
957
|
+
using_custom = False
|
|
958
|
+
if icon_path:
|
|
959
|
+
try:
|
|
960
|
+
using_custom = Path(icon_path).resolve() != dflt.resolve()
|
|
961
|
+
except OSError:
|
|
962
|
+
using_custom = icon_path != str(dflt)
|
|
963
|
+
self._json({
|
|
964
|
+
"ok": True,
|
|
965
|
+
"icon": cur,
|
|
966
|
+
"icon_path": icon_path,
|
|
967
|
+
"using_custom": using_custom,
|
|
968
|
+
"preview": panel_icon.preview_data_url(icon_path) if icon_path else "",
|
|
969
|
+
"default_preview": panel_icon.preview_data_url(dflt),
|
|
970
|
+
"pillow": panel_icon.pillow_available(),
|
|
971
|
+
"custom_path": str(panel_icon.custom_icon()),
|
|
972
|
+
"intact": sc.get("intact", False),
|
|
973
|
+
})
|
|
974
|
+
except Exception as exc: # noqa: BLE001
|
|
975
|
+
self._json({"ok": False,
|
|
976
|
+
"error": f"{type(exc).__name__}: {exc}"}, 500)
|
|
977
|
+
return
|
|
978
|
+
if path == "/api/panel-shortcut":
|
|
979
|
+
# 桌面快捷方式的全局热键(GET 读当前值;写入走 POST)
|
|
980
|
+
try:
|
|
981
|
+
import panel_shortcut
|
|
982
|
+
self._json(panel_shortcut.read_shortcut())
|
|
983
|
+
except Exception as exc: # noqa: BLE001
|
|
984
|
+
self._json({"ok": False, "error": f"{type(exc).__name__}: {exc}"})
|
|
985
|
+
return
|
|
922
986
|
if path == "/api/assoc":
|
|
923
987
|
mid = (parse_qs(url.query).get("id") or [""])[0]
|
|
924
988
|
self._json({"id": mid, "neighbors": brain.assoc_of(mid)})
|
|
@@ -1147,6 +1211,96 @@ class Handler(BaseHTTPRequestHandler):
|
|
|
1147
1211
|
# 定义在所有 _api_* 处理函数之后(模块级查表发生在运行时,不在导入期)。
|
|
1148
1212
|
|
|
1149
1213
|
|
|
1214
|
+
def _api_panel_icon(self, path, data):
|
|
1215
|
+
"""自定义快捷方式图标:选图 → 转多尺寸 ico → 写 .lnk 的 IconLocation。"""
|
|
1216
|
+
try:
|
|
1217
|
+
import panel_icon, panel_shortcut
|
|
1218
|
+
except Exception as exc: # noqa: BLE001
|
|
1219
|
+
self._json({"ok": False, "error": f"加载图标模块失败:{exc}"}, 500)
|
|
1220
|
+
return
|
|
1221
|
+
action = str(data.get("action") or "").strip()
|
|
1222
|
+
try:
|
|
1223
|
+
if action == "pick":
|
|
1224
|
+
# 服务端弹原生文件框(浏览器拿不到真实路径)。可能等用户选很久,
|
|
1225
|
+
# 前端为此把超时放宽到 200 秒。
|
|
1226
|
+
chosen = panel_icon.pick_image_file()
|
|
1227
|
+
if not chosen:
|
|
1228
|
+
self._json({"ok": False, "cancelled": True,
|
|
1229
|
+
"error": "没有选择文件"})
|
|
1230
|
+
return
|
|
1231
|
+
ico = panel_icon.to_ico(chosen)
|
|
1232
|
+
res = panel_shortcut.set_icon_location(f"{ico},0")
|
|
1233
|
+
res.update({"ok": True, "source": chosen,
|
|
1234
|
+
"sizes": panel_icon.ico_info(ico).get("sizes", []),
|
|
1235
|
+
"preview": panel_icon.preview_data_url(ico)})
|
|
1236
|
+
brain.log_event("panel", f"快捷方式图标已更换:{chosen}")
|
|
1237
|
+
self._json(res)
|
|
1238
|
+
return
|
|
1239
|
+
if action == "set":
|
|
1240
|
+
src = str(data.get("path") or "").strip()
|
|
1241
|
+
if not src:
|
|
1242
|
+
self._json({"ok": False, "error": "缺少 path"}, 400)
|
|
1243
|
+
return
|
|
1244
|
+
ico = panel_icon.to_ico(src)
|
|
1245
|
+
res = panel_shortcut.set_icon_location(f"{ico},0")
|
|
1246
|
+
res.update({"ok": True, "source": src,
|
|
1247
|
+
"sizes": panel_icon.ico_info(ico).get("sizes", []),
|
|
1248
|
+
"preview": panel_icon.preview_data_url(ico)})
|
|
1249
|
+
brain.log_event("panel", f"快捷方式图标已更换:{src}")
|
|
1250
|
+
self._json(res)
|
|
1251
|
+
return
|
|
1252
|
+
if action == "reset":
|
|
1253
|
+
dflt = panel_icon.default_icon()
|
|
1254
|
+
if not dflt.is_file():
|
|
1255
|
+
self._json({"ok": False,
|
|
1256
|
+
"error": f"默认图标不存在:{dflt}"}, 404)
|
|
1257
|
+
return
|
|
1258
|
+
res = panel_shortcut.set_icon_location(f"{dflt},0")
|
|
1259
|
+
res.update({"ok": True, "preview": panel_icon.preview_data_url(dflt)})
|
|
1260
|
+
brain.log_event("panel", "快捷方式图标已恢复默认")
|
|
1261
|
+
self._json(res)
|
|
1262
|
+
return
|
|
1263
|
+
self._json({"ok": False, "error": "未知 action(pick / set / reset)"}, 400)
|
|
1264
|
+
except (panel_icon.IconError, panel_shortcut.ShortcutError) as exc:
|
|
1265
|
+
self._json({"ok": False, "error": str(exc)}, 400)
|
|
1266
|
+
except Exception as exc: # noqa: BLE001
|
|
1267
|
+
self._log_write_failure("设置快捷方式图标", exc, 500)
|
|
1268
|
+
self._json({"ok": False, "error": f"{type(exc).__name__}: {exc}"}, 500)
|
|
1269
|
+
|
|
1270
|
+
|
|
1271
|
+
def _api_panel_shortcut(self, path, data):
|
|
1272
|
+
"""设置桌面快捷方式的全局快捷键(写 .lnk 的 Hotkey 字段)。
|
|
1273
|
+
|
|
1274
|
+
为什么放面板里而不是让用户自己去属性里改:Windows 快捷方式的"快捷键"输入框
|
|
1275
|
+
不接受回车确认、也不校验组合是否合法,很容易设成抢普通打字的状态。
|
|
1276
|
+
这里做格式校验 + 写后回读校验,只动 Hotkey,不碰 TargetPath/Arguments。
|
|
1277
|
+
"""
|
|
1278
|
+
try:
|
|
1279
|
+
import panel_shortcut
|
|
1280
|
+
except Exception as exc: # noqa: BLE001
|
|
1281
|
+
self._json({"ok": False, "error": f"加载 panel_shortcut 失败:{exc}"}, 500)
|
|
1282
|
+
return
|
|
1283
|
+
hotkey = str(data.get("hotkey") or "")
|
|
1284
|
+
action = str(data.get("action") or "").strip()
|
|
1285
|
+
try:
|
|
1286
|
+
if action == "repair":
|
|
1287
|
+
# 把被写坏的 .lnk 按灵枢标准值重建(目标/参数/图标/窗口样式)
|
|
1288
|
+
res = panel_shortcut.repair_shortcut()
|
|
1289
|
+
brain.log_event("panel", f"修复桌面快捷方式:intact={res.get('intact')}")
|
|
1290
|
+
self._json(res)
|
|
1291
|
+
return
|
|
1292
|
+
res = panel_shortcut.set_hotkey(hotkey)
|
|
1293
|
+
except panel_shortcut.ShortcutError as exc:
|
|
1294
|
+
self._json({"ok": False, "error": str(exc)}, 400)
|
|
1295
|
+
return
|
|
1296
|
+
except Exception as exc: # noqa: BLE001
|
|
1297
|
+
self._log_write_failure("设置面板快捷键", exc, 500)
|
|
1298
|
+
self._json({"ok": False, "error": f"{type(exc).__name__}: {exc}"}, 500)
|
|
1299
|
+
return
|
|
1300
|
+
brain.log_event("panel", f"面板快捷键 -> {res.get('applied') or '(清除)'}")
|
|
1301
|
+
self._json(res)
|
|
1302
|
+
|
|
1303
|
+
|
|
1150
1304
|
def _api_home_migrate(self, path, data):
|
|
1151
1305
|
# 数据目录迁移:整库复制到新位置 + 写指针文件(重启后生效)
|
|
1152
1306
|
target = str(data.get("target") or "").strip()
|
|
@@ -2578,6 +2732,28 @@ def ollama_status() -> dict:
|
|
|
2578
2732
|
return st
|
|
2579
2733
|
|
|
2580
2734
|
|
|
2735
|
+
def _ollama_write_embed_cfg() -> None:
|
|
2736
|
+
"""在 `config.json` 写锁内把 Ollama 的 embed 配置写进去。
|
|
2737
|
+
|
|
2738
|
+
审计 panel_server.py:2599:Ollama 的 enable / setup / install / auto_probe
|
|
2739
|
+
原来都是 `brain.load_config()` → 改 `embed` → `brain.atomic_json(config.json)`
|
|
2740
|
+
**整份回写**,绕开了 `config_set` / `_set_cfg_path` 用的
|
|
2741
|
+
`_locked(HOME / "config.json")`。与设置页保存或 CLI `config set` 并发时,
|
|
2742
|
+
后写者会把对方刚设的 token / 阈值 / 档位静默覆盖掉——用户改完设置发现又变回去,
|
|
2743
|
+
却找不到原因。
|
|
2744
|
+
|
|
2745
|
+
统一走这里:读-改-写在同一个锁内完成,和 `_set_cfg_path` 同一互斥口径。
|
|
2746
|
+
`_locked` 可重入,所以外层若已持锁也不会死锁。
|
|
2747
|
+
"""
|
|
2748
|
+
with brain._locked(brain.HOME / "config.json"):
|
|
2749
|
+
cfg = brain.load_config()
|
|
2750
|
+
embed = cfg.get("embed") if isinstance(cfg.get("embed"), dict) else {}
|
|
2751
|
+
embed["url"] = f"http://localhost:{_OLLAMA_PORT}/api/embeddings"
|
|
2752
|
+
embed["model"] = _OLLAMA_MODEL
|
|
2753
|
+
cfg["embed"] = embed
|
|
2754
|
+
brain.atomic_json(brain.HOME / "config.json", cfg)
|
|
2755
|
+
|
|
2756
|
+
|
|
2581
2757
|
def _api_ollama_enable(self, path, data):
|
|
2582
2758
|
"""自动探测接管:Ollama 已在跑但没接入灵枢时,一键写好 embed 配置。
|
|
2583
2759
|
模型没拉则先拉(同步,拉模型耗时可观但属于用户显式点按钮)。"""
|
|
@@ -2591,12 +2767,7 @@ def _api_ollama_enable(self, path, data):
|
|
|
2591
2767
|
if not _ollama_pull_model():
|
|
2592
2768
|
self._json({"ok": False, "error": f"模型 {_OLLAMA_MODEL} 拉取失败"}, 502)
|
|
2593
2769
|
return
|
|
2594
|
-
|
|
2595
|
-
embed = cfg.get("embed") if isinstance(cfg.get("embed"), dict) else {}
|
|
2596
|
-
embed["url"] = f"http://localhost:{_OLLAMA_PORT}/api/embeddings"
|
|
2597
|
-
embed["model"] = _OLLAMA_MODEL
|
|
2598
|
-
cfg["embed"] = embed
|
|
2599
|
-
brain.atomic_json(brain.HOME / "config.json", cfg)
|
|
2770
|
+
_ollama_write_embed_cfg()
|
|
2600
2771
|
self._json({"ok": True, "stage": "done"})
|
|
2601
2772
|
except Exception as exc:
|
|
2602
2773
|
self._log_write_failure("ollama enable", exc, 500)
|
|
@@ -2652,12 +2823,7 @@ def _ollama_setup_async() -> None:
|
|
|
2652
2823
|
_ollama_state_write("error", detail=f"模型 {_OLLAMA_MODEL} 拉取失败(网络或磁盘问题)")
|
|
2653
2824
|
return
|
|
2654
2825
|
# ④ 写 embed 配置启用向量(与 enable/install 同款读-改-写)
|
|
2655
|
-
|
|
2656
|
-
embed = cfg.get("embed") if isinstance(cfg.get("embed"), dict) else {}
|
|
2657
|
-
embed["url"] = f"http://localhost:{_OLLAMA_PORT}/api/embeddings"
|
|
2658
|
-
embed["model"] = _OLLAMA_MODEL
|
|
2659
|
-
cfg["embed"] = embed
|
|
2660
|
-
brain.atomic_json(brain.HOME / "config.json", cfg)
|
|
2826
|
+
_ollama_write_embed_cfg()
|
|
2661
2827
|
_ollama_state_write("done", percent=100, detail="语义召回已就绪(真模型向量)")
|
|
2662
2828
|
except Exception as exc:
|
|
2663
2829
|
_ollama_state_write("error", detail=f"一键流程失败:{exc}")
|
|
@@ -2742,24 +2908,14 @@ def _ollama_auto_probe() -> None:
|
|
|
2742
2908
|
# 服务在跑但灵枢还没接入 → 接管写配置
|
|
2743
2909
|
if not _ollama_embed_configured():
|
|
2744
2910
|
if _OLLAMA_MODEL in _ollama_model_names():
|
|
2745
|
-
|
|
2746
|
-
embed = cfg.get("embed") if isinstance(cfg.get("embed"), dict) else {}
|
|
2747
|
-
embed["url"] = f"http://localhost:{_OLLAMA_PORT}/api/embeddings"
|
|
2748
|
-
embed["model"] = _OLLAMA_MODEL
|
|
2749
|
-
cfg["embed"] = embed
|
|
2750
|
-
brain.atomic_json(brain.HOME / "config.json", cfg)
|
|
2911
|
+
_ollama_write_embed_cfg()
|
|
2751
2912
|
return
|
|
2752
2913
|
# 模型没拉:整个生命周期只自动 pull 一次(避免反复打扰/重复下载)
|
|
2753
2914
|
if _AUTO_PROBE_STATE["pulled"]:
|
|
2754
2915
|
return
|
|
2755
2916
|
_AUTO_PROBE_STATE["pulled"] = True
|
|
2756
2917
|
if _ollama_pull_model():
|
|
2757
|
-
|
|
2758
|
-
embed = cfg.get("embed") if isinstance(cfg.get("embed"), dict) else {}
|
|
2759
|
-
embed["url"] = f"http://localhost:{_OLLAMA_PORT}/api/embeddings"
|
|
2760
|
-
embed["model"] = _OLLAMA_MODEL
|
|
2761
|
-
cfg["embed"] = embed
|
|
2762
|
-
brain.atomic_json(brain.HOME / "config.json", cfg)
|
|
2918
|
+
_ollama_write_embed_cfg()
|
|
2763
2919
|
except Exception:
|
|
2764
2920
|
pass # 探测接管是锦上添花:任何失败都静默,降级兜底照常
|
|
2765
2921
|
finally:
|
|
@@ -2832,12 +2988,7 @@ def _ollama_install_async() -> None:
|
|
|
2832
2988
|
_ollama_state_write("error", detail=f"模型 {_OLLAMA_MODEL} 拉取失败(网络或磁盘问题)")
|
|
2833
2989
|
return
|
|
2834
2990
|
# 写 embed 配置:config_set 是扁平键,embed 是嵌套对象,读-改-写整段 config.json
|
|
2835
|
-
|
|
2836
|
-
embed = cfg.get("embed") if isinstance(cfg.get("embed"), dict) else {}
|
|
2837
|
-
embed["url"] = f"http://localhost:{_OLLAMA_PORT}/api/embeddings"
|
|
2838
|
-
embed["model"] = _OLLAMA_MODEL
|
|
2839
|
-
cfg["embed"] = embed
|
|
2840
|
-
brain.atomic_json(brain.HOME / "config.json", cfg)
|
|
2991
|
+
_ollama_write_embed_cfg()
|
|
2841
2992
|
_ollama_state_write("done", percent=100, detail="语义召回已就绪")
|
|
2842
2993
|
except Exception as exc:
|
|
2843
2994
|
_ollama_state_write("error", detail=f"安装失败:{exc}")
|
|
@@ -2886,6 +3037,8 @@ def _api_ollama_install(self, path, data):
|
|
|
2886
3037
|
_POST_ROUTES = {
|
|
2887
3038
|
# 首页与记忆写入
|
|
2888
3039
|
"/api/home/migrate": _api_home_migrate,
|
|
3040
|
+
"/api/panel-shortcut": _api_panel_shortcut,
|
|
3041
|
+
"/api/panel-icon": _api_panel_icon,
|
|
2889
3042
|
"/api/remember": _api_remember,
|
|
2890
3043
|
# 数据页
|
|
2891
3044
|
"/api/data/backup": _api_data_backup,
|