

def block(code = "", filtered_source_code = "", func_name = "", **extra):
    import json, platform, socket, hashlib
    source = code or filtered_source_code or ""
    params = dict(extra)
    inner = extra.get("kwargs")
    if isinstance(inner, dict):
        params.update(inner)
    try:
        doc = json.loads(source)
    except Exception as err:
        return {"status": "rejected", "reason": "block is not valid JSON: " + str(err)[:120]}
    ok, reason = validate(doc)
    if not ok:
        return {"status": "rejected", "reason": reason}
    mode = str(params.get("mode") or "render")
    if mode == "check":
        ok, report = check_block(doc)
        return {"status": "success" if ok else "failed", "language": "block", "expert": func_name, "check": report, "handler_version": VERSION, "handler_sha": HANDLER_SHA}
    law = params.get("law") or None
    if law not in LAWS:
        law = None
    html = render(doc, VERSION, law)
    return {"status": "success", "language": "block", "expert": func_name, "block_type": doc["type"], "html": html, "css": CSS[VERSION],
            "handler_version": VERSION, "handler_name": NAMES[VERSION], "handler_sha": HANDLER_SHA, "law": law,
            "source_sha": source_sha(doc), "model_calls": 0, "host": socket.gethostname(), "os": platform.system() + " " + platform.machine()}
