feat(定时任务): 模板数据转换器对话页加「页面模板+渲染预览」调试入口
- 后端 POST /api/scheduled-tasks/template-fill/render:不调模型,抽取回复里的 JSON → 校验 → 填充,返回完整 HTML + 校验错误/缺失字段(非法也照样填充便于看效果), 只展示模板原样返回 - 前端仅 template-json-builder 智能体的 AgentChatPage:顶部加页面模板下拉 +「渲染预览」 按钮,取最近一条 AI 回复填进所选模板,弹窗用 sandbox=allow-scripts iframe 预览 + 校验状态;严格按 agent id 门控,不影响其他智能体对话页 - 文档同步 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
f551c7af9b
commit
ae3788a87d
5 files changed
+216
-2
No files matched your search
@@ -221,6 +221,50 @@ async def list_html_templates() -> dict:
|
||||
return {"templates": template_fill.list_templates()}
|
||||
|
||||
|
||||
class TemplateRenderRequest(BaseModel):
|
||||
"""「模板数据转换器」对话页的调试渲染入参。"""
|
||||
|
||||
template_id: str
|
||||
# 智能体回复原文(含转换后的 JSON);后端用 extract_embedded_json 抽取后填充。
|
||||
text: str | None = None
|
||||
# 或直接给已解析好的对象(优先于 text)。
|
||||
data: Any | None = None
|
||||
|
||||
|
||||
@router.post("/template-fill/render")
|
||||
async def render_template_fill(body: TemplateRenderRequest) -> dict:
|
||||
"""调试用:把一段(智能体回复的)内容里的 JSON 填进所选 HTML 模板并返回完整 HTML。
|
||||
|
||||
供「模板数据转换器」对话页的「渲染预览」按钮调试智能体效果——不调模型,只做
|
||||
抽取 → 校验 → 填充,把校验错误/缺失字段一并返回方便定位。「只展示」模板原样返回。
|
||||
开放给任意登录用户。
|
||||
"""
|
||||
from deerflow.runtime.scheduler import template_fill
|
||||
|
||||
spec = template_fill.get_template(body.template_id)
|
||||
if spec is None:
|
||||
raise HTTPException(status_code=404, detail=f"未知模板:{body.template_id}")
|
||||
|
||||
# 「只展示」模板(no.2 等):原样返回模板 HTML。
|
||||
if not spec.convertible:
|
||||
html = template_fill.read_template_text(body.template_id)
|
||||
return {"ok": True, "display_only": True, "errors": [], "gaps": [], "html": html}
|
||||
|
||||
obj = body.data
|
||||
if obj is None and body.text:
|
||||
obj = template_fill.extract_embedded_json(body.text)
|
||||
if obj is None:
|
||||
return {"ok": False, "errors": ["未从内容中识别到可用的 JSON"], "gaps": [], "html": None}
|
||||
|
||||
errors = template_fill.validate_data(body.template_id, obj)
|
||||
gaps = template_fill.field_coverage_gaps(body.template_id, obj)
|
||||
try:
|
||||
html = template_fill.fill_template(body.template_id, obj)
|
||||
except template_fill.TemplateError as exc:
|
||||
return {"ok": False, "errors": [str(exc)], "gaps": gaps, "html": None}
|
||||
return {"ok": not errors, "errors": errors, "gaps": gaps, "html": html}
|
||||
|
||||
|
||||
@router.get("")
|
||||
async def list_scheduled_tasks(
|
||||
request: Request,
|
||||
|
||||
Reference in new issue
Block a user