sync update from LAN repo (source master @ ca48c4ec)

This commit is contained in:
gozeros committed 2026-11-05 10:53:54 +08:00
1 parent 8bc8b0e082
commit ea9dcff9c0
873 files changed
+107866 -14011

No files matched your search

@@ -18,7 +18,13 @@ HTML 模板需要的 ``DATA`` 结构后,本模块负责把数据**填充**进模
公开入口:``list_templates`` / ``get_template`` / ``reference_data`` /
``schema_skeleton_json`` / ``validate_data`` / ``field_coverage_gaps`` /
``shape_mismatches`` / ``fill_template``。
``shape_mismatches`` / ``fill_template`` / ``invalidate_cache``。
模板来源(读取顺序):运行时存储 :mod:`.template_store`
(``{base_dir}/html-templates/<id>/``,模板管理页可上传/编辑/新增,内置模板由
:func:`template_store.ensure_seeded` 启动 seed,缺失才复制、绝不覆盖修改)→ 随包
注册表 :data:`TEMPLATES`(下方静态清单)兜底。写操作经 ``template_store`` 完成,
写入后调 :func:`invalidate_cache` 清掉本模块的 lru_cache。
"""
from __future__ import annotations
@@ -123,7 +129,8 @@ class TemplateSpec:
convertible: bool = True
# 已注册模板。新增 no.2/no.3 时在此追加一条即可——前端下拉、调度器填充全自动生效。
# 已注册模板(随包 seed 源 + 存储缺失时的兜底注册表)。新增模板时在此追加一条
# 即可——前端下拉、调度器填充全自动生效;运行时增删改走 template_store。
TEMPLATES: tuple[TemplateSpec, ...] = (
TemplateSpec(
id="no1",
@@ -341,30 +348,90 @@ class TemplateError(Exception):
def list_templates() -> list[dict[str, Any]]:
"""前端下拉用的轻量清单(只含 id/name/description/convertible,不含庞大数据)。"""
"""前端下拉用的轻量清单(只含 id/name/description/convertible,不含庞大数据)。
优先读运行时存储(template_store,含管理页上传/自建的模板);存储整体不可用时
回退随包静态注册表,保证「还没 seed / 存储目录损坏」时功能仍可用。
"""
from deerflow.runtime.scheduler import template_store
try:
entries = template_store.list_templates()
except Exception:
entries = []
if entries:
return [
{
"id": e["id"],
"name": e["name"],
"description": e.get("description") or "",
"convertible": bool(e.get("convertible")),
}
for e in entries
]
return [
{"id": t.id, "name": t.name, "description": t.description, "convertible": t.convertible}
for t in TEMPLATES
]
def _store_template_file(template_id: str) -> Path | None:
"""存储里该模板的正文路径;不存在(未 seed/自建被删)返回 None。"""
from deerflow.runtime.scheduler import template_store
path = template_store.store_template_file(template_id)
return path if path.is_file() else None
def get_template(template_id: str) -> TemplateSpec | None:
"""模板注册信息:存储 meta 优先(动态,含管理页修改),随包注册表兜底。"""
from deerflow.runtime.scheduler import template_store
try:
meta = template_store.get_template_meta(template_id)
except Exception:
meta = None
if meta is not None:
return TemplateSpec(
id=str(meta["id"]),
name=str(meta.get("name") or meta["id"]),
description=str(meta.get("description") or ""),
# 存储模板的正文路径由 _template_path 按 id 解析,这里的 file 仅占位。
file=f"{meta['id']}/template.html",
data_var="DATA",
manifest_var=str(meta.get("manifest_var") or ""),
convertible=bool(meta.get("convertible")),
)
return _TEMPLATES_BY_ID.get(template_id)
def invalidate_cache() -> None:
"""清掉 reference_data / schema_skeleton_json 的 lru_cache。
template_store 的写操作(创建/编辑/上传覆盖/重置/删除)后必须调用,否则引擎
仍按改前的旧 DATA 做校验与骨架注入。
"""
reference_data.cache_clear()
schema_skeleton_json.cache_clear()
def is_convertible(template_id: str) -> bool:
spec = _TEMPLATES_BY_ID.get(template_id)
spec = get_template(template_id)
return bool(spec and spec.convertible)
def _require(template_id: str) -> TemplateSpec:
spec = _TEMPLATES_BY_ID.get(template_id)
spec = get_template(template_id)
if spec is None:
raise TemplateError(f"未知模板 id:{template_id!r}")
return spec
def _template_path(spec: TemplateSpec) -> Path:
# 存储副本优先(管理页编辑/上传的新版);没有才读随包静态文件。
store_file = _store_template_file(spec.id)
if store_file is not None:
return store_file
return _TEMPLATES_ROOT / spec.file