Skip to content

[Bug] In the AI dialogue node the tool directly outputs an <html_rander> tag causing incorrect display #4103

@WongHohin

Description

@WongHohin

Contact Information

No response

MaxKB Version

2.1.1

Problem Description

在AI节点调用工具,GPT5模型,打开返回内容,若工具直接返回<html_rander>内容,<html_rander>标签后面的文字输出会包在代码框内。

Image

在执行详情中是正常显示的:

Image

Steps to Reproduce

工具的作用是根据json动态生成表单html,以下是工具的代码:
def build_form(data: dict) -> str:
title = data.get("title", "")
params = data.get("params", [])
btn_lab = data.get("button_label", "提交")
s_type = data.get("submit_type", "text")

# ---------- 生成控件 ----------
rows = []
for p in params:
    label = p.get("label", "")
    name = p.get("name", "")
    value = p.get("value", "")
    typ = p.get("type", "text")
    # 仅当 required == 1 才在校验阶段检查
    required = p.get("required", 0) == 1

    label_html = f'<div class="bf-label">{"*" if required else ""}{label}</div>'

    if typ == "password":
        control = f'<input type="password" class="bf-input {name}" value="{value}" />'
    elif typ == "options":
        opts = "".join(
            f'<option value="{o}" {"selected" if o == value else ""}>{o}</option>'
            for o in p.get("options", [])
        )
        control = f'<select class="bf-select {name}">{opts}</select>'
    elif typ == "date":
        control = f'<input type="date" class="bf-input {name}" value="{value}" />'
    elif typ == "datetime":
        control = f'<input type="datetime-local" class="bf-input {name}" value="{value}" />'
    else:  # text
        control = f'<input type="text" class="bf-input {name}" value="{value}" />'

    rows.append(f"""
    <div class="bf-row">
        {label_html}
        <div class="bf-control">{control}</div>
    </div>""")

rows_html = "\n".join(rows)

# ---------- 校验:仅 required == 1 ----------
check_js = "\n".join(
    f'if (!target.querySelector(".{p["name"]}").value.trim()) {{ alert("请填写 {p["label"]}"); return; }}'
    for p in params if p.get("required") == 1
)

# ---------- 发送 ----------
if s_type == "json":
    kv_js = ", ".join(f'{p["name"]}' for p in params)
    send_js = f"""
    const obj = {{ {kv_js} }};
    sendMessage(JSON.stringify(obj, null, 2));"""
else:
    parts = ' + ", " + '.join([f'"{p["name"]}:" + {p["name"]}' for p in params])
    send_js = f"""
    const text = `{title},参数:[${{{parts}}}]`;
    sendMessage(text);"""

# ---------- 样式 ----------
style = """
<style> .bf-container{max-width:480px;margin:40px auto;background:#fff;border-radius:12px;box-shadow:0 8px 30px rgba(0,0,0,.08);padding:32px 40px;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial;} .bf-title{font-size:22px;font-weight:600;margin-bottom:24px;color:#222;} .bf-row{display:flex;align-items:center;margin-bottom:20px;} .bf-label{flex:0 0 100px;font-size:15px;color:#444;} .bf-control{flex:1;} .bf-input,.bf-select{width:100%;padding:10px 14px;font-size:15px;border:1px solid #ddd;border-radius:6px;transition:all .2s;} .bf-input:focus,.bf-select:focus{border-color:#4f46e5;outline:none;box-shadow:0 0 0 3px rgba(79,70,229,.15);} .bf-btn{margin-top:8px;width:100%;padding:12px;font-size:16px;border:none;border-radius:6px;background:#4f46e5;color:#fff;cursor:pointer;transition:background .2s;} .bf-btn:hover{background:#4338ca;} @media(max-width:480px){.bf-container{padding:24px 20px;}.bf-label{flex:0 0 80px;font-size:14px;}} </style>"""
# ---------- 最终 HTML ----------
html = f"""<html_rander>

{style}


{title}

{rows_html}

{btn_lab}

<script>
    function bfSubmit(node) {{
        const target = node.parentNode;

{check_js}""" + "".join(f"""
const {p['name']} = target.querySelector(".{p['name']}").value;""" for p in params) + f"""
{send_js}
}}
</script>
</html_rander>"""
return html.strip()

The expected correct result

No response

Related log output

Additional Information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions