import jingrow

@jingrow.whitelist()
def execute(context=None, inputs=None, config=None, **kwargs):
    if context is None:
        context = kwargs.get("context", {})
    if inputs is None:
        inputs = kwargs.get("inputs", {})
    if config is None:
        config = kwargs.get("config", {})
 
    # jingrow.log_error("input_record 节点 inputs汇总", f"inputs={inputs}, config={config}, context={context}")

    pagetype = inputs.get("pagetype")
    name = inputs.get("name")
    if not (pagetype and name):
        pagetype = config.get("pagetype")
        name = config.get("name")
    if not pagetype or not name:
        return {"success": False, "error": "缺少pagetype或name"}
    try:
        pg = jingrow.get_pg(pagetype, name)
        data = pg.as_dict() if hasattr(pg, "as_dict") else dict(pg.__dict__)
        data["success"] = True
        # jingrow.log_error("input_record 节点 pg.as_dict()", repr(data))
        return data
    except Exception as e:
        jingrow.log_error("input_record 节点异常", str(e))
        return {"success": False, "error": str(e)} 